#
google_cloud_pubsub/generated/gapic_dataplane/
transport.rs

    1// Copyright 2025 Google LLC
    2//
    3// Licensed under the Apache License, Version 2.0 (the "License");
    4// you may not use this file except in compliance with the License.
    5// You may obtain a copy of the License at
    6//
    7//     https://www.apache.org/licenses/LICENSE-2.0
    8//
    9// Unless required by applicable law or agreed to in writing, software
    10// distributed under the License is distributed on an "AS IS" BASIS,
    11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12// See the License for the specific language governing permissions and
    13// limitations under the License.
    14//
    15// Code generated by sidekick. DO NOT EDIT.
    16
    17use crate::Result;
    18#[allow(unused_imports)]
    19use gax::error::Error;
    20
    21const DEFAULT_HOST: &str = "https://pubsub.googleapis.com";
    22
    23mod info {
    24    const NAME: &str = env!("CARGO_PKG_NAME");
    25    const VERSION: &str = env!("CARGO_PKG_VERSION");
    26    lazy_static::lazy_static! {
    27        pub(crate) static ref X_GOOG_API_CLIENT_HEADER: String = {
    28            let ac = gaxi::api_header::XGoogApiClient{
    29                name:          NAME,
    30                version:       VERSION,
    31                library_type:  gaxi::api_header::GAPIC,
    32            };
    33            ac.grpc_header_value()
    34        };
    35    }
    36}
    37
    38/// Implements [Publisher](super::stub::Publisher) using a Tonic-generated client.
    39#[derive(Clone)]
    40pub struct Publisher {
    41    pub(crate) inner: gaxi::grpc::Client,
    42}
    43
    44impl std::fmt::Debug for Publisher {
    45    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
    46        f.debug_struct("Publisher")
    47            .field("inner", &self.inner)
    48            .finish()
    49    }
    50}
    51
    52impl Publisher {
    53    pub async fn new(config: gaxi::options::ClientConfig) -> gax::client_builder::Result<Self> {
    54        let inner = gaxi::grpc::Client::new(config, DEFAULT_HOST).await?;
    55        Ok(Self { inner })
    56    }
    57}
    58
    59impl super::stub::Publisher for Publisher {
    60    async fn publish(
    61        &self,
    62        req: crate::model::PublishRequest,
    63        options: gax::options::RequestOptions,
    64    ) -> Result<gax::response::Response<crate::model::PublishResponse>> {
    65        use gaxi::prost::ToProto;
    66        let options = gax::options::internal::set_default_idempotency(options, false);
    67        let extensions = {
    68            let mut e = tonic::Extensions::new();
    69            e.insert(tonic::GrpcMethod::new(
    70                "google.pubsub.v1.Publisher",
    71                "Publish",
    72            ));
    73            e
    74        };
    75        let path = http::uri::PathAndQuery::from_static("/google.pubsub.v1.Publisher/Publish");
    76        let x_goog_request_params = [Some(&req)
    77            .map(|m| &m.topic)
    78            .map(|s| s.as_str())
    79            .map(|v| format!("topic={v}"))]
    80        .into_iter()
    81        .flatten()
    82        .fold(String::new(), |b, p| b + "&" + &p);
    83
    84        type TR = crate::google::pubsub::v1::PublishResponse;
    85        self.inner
    86            .execute(
    87                extensions,
    88                path,
    89                req.to_proto().map_err(Error::deser)?,
    90                options,
    91                &info::X_GOOG_API_CLIENT_HEADER,
    92                &x_goog_request_params,
    93            )
    94            .await
    95            .and_then(gaxi::grpc::to_gax_response::<TR, crate::model::PublishResponse>)
    96    }
    97}
    98
    99/// Implements [Subscriber](super::stub::Subscriber) using a Tonic-generated client.
    100#[derive(Clone)]
    101pub struct Subscriber {
    102    pub(crate) inner: gaxi::grpc::Client,
    103}
    104
    105impl std::fmt::Debug for Subscriber {
    106    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
    107        f.debug_struct("Subscriber")
    108            .field("inner", &self.inner)
    109            .finish()
    110    }
    111}
    112
    113impl Subscriber {
    114    pub async fn new(config: gaxi::options::ClientConfig) -> gax::client_builder::Result<Self> {
    115        let inner = gaxi::grpc::Client::new(config, DEFAULT_HOST).await?;
    116        Ok(Self { inner })
    117    }
    118}
    119
    120impl super::stub::Subscriber for Subscriber {
    121    async fn modify_ack_deadline(
    122        &self,
    123        req: crate::model::ModifyAckDeadlineRequest,
    124        options: gax::options::RequestOptions,
    125    ) -> Result<gax::response::Response<()>> {
    126        use gaxi::prost::ToProto;
    127        let options = gax::options::internal::set_default_idempotency(options, false);
    128        let extensions = {
    129            let mut e = tonic::Extensions::new();
    130            e.insert(tonic::GrpcMethod::new(
    131                "google.pubsub.v1.Subscriber",
    132                "ModifyAckDeadline",
    133            ));
    134            e
    135        };
    136        let path =
    137            http::uri::PathAndQuery::from_static("/google.pubsub.v1.Subscriber/ModifyAckDeadline");
    138        let x_goog_request_params = [Some(&req)
    139            .map(|m| &m.subscription)
    140            .map(|s| s.as_str())
    141            .map(|v| format!("subscription={v}"))]
    142        .into_iter()
    143        .flatten()
    144        .fold(String::new(), |b, p| b + "&" + &p);
    145
    146        type TR = ();
    147        self.inner
    148            .execute(
    149                extensions,
    150                path,
    151                req.to_proto().map_err(Error::deser)?,
    152                options,
    153                &info::X_GOOG_API_CLIENT_HEADER,
    154                &x_goog_request_params,
    155            )
    156            .await
    157            .and_then(gaxi::grpc::to_gax_response::<TR, ()>)
    158    }
    159
    160    async fn acknowledge(
    161        &self,
    162        req: crate::model::AcknowledgeRequest,
    163        options: gax::options::RequestOptions,
    164    ) -> Result<gax::response::Response<()>> {
    165        use gaxi::prost::ToProto;
    166        let options = gax::options::internal::set_default_idempotency(options, false);
    167        let extensions = {
    168            let mut e = tonic::Extensions::new();
    169            e.insert(tonic::GrpcMethod::new(
    170                "google.pubsub.v1.Subscriber",
    171                "Acknowledge",
    172            ));
    173            e
    174        };
    175        let path = http::uri::PathAndQuery::from_static("/google.pubsub.v1.Subscriber/Acknowledge");
    176        let x_goog_request_params = [Some(&req)
    177            .map(|m| &m.subscription)
    178            .map(|s| s.as_str())
    179            .map(|v| format!("subscription={v}"))]
    180        .into_iter()
    181        .flatten()
    182        .fold(String::new(), |b, p| b + "&" + &p);
    183
    184        type TR = ();
    185        self.inner
    186            .execute(
    187                extensions,
    188                path,
    189                req.to_proto().map_err(Error::deser)?,
    190                options,
    191                &info::X_GOOG_API_CLIENT_HEADER,
    192                &x_goog_request_params,
    193            )
    194            .await
    195            .and_then(gaxi::grpc::to_gax_response::<TR, ()>)
    196    }
    197}