#
google_cloud_pubsub/generated/gapic_dataplane/model/
serialize.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
    17#[allow(unused_imports)]
    18use super::*;
    19
    20#[doc(hidden)]
    21impl serde::ser::Serialize for super::PubsubMessage {
    22    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    23    where
    24        S: serde::ser::Serializer,
    25    {
    26        use serde::ser::SerializeMap;
    27        #[allow(unused_imports)]
    28        use std::option::Option::Some;
    29        let mut state = serializer.serialize_map(std::option::Option::None)?;
    30        if !self.data.is_empty() {
    31            struct __With<'a>(&'a ::bytes::Bytes);
    32            impl<'a> serde::ser::Serialize for __With<'a> {
    33                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    34                where
    35                    S: serde::ser::Serializer,
    36                {
    37                    serde_with::As::<serde_with::base64::Base64>::serialize(self.0, serializer)
    38                }
    39            }
    40            state.serialize_entry("data", &__With(&self.data))?;
    41        }
    42        if !self.attributes.is_empty() {
    43            state.serialize_entry("attributes", &self.attributes)?;
    44        }
    45        if !self.message_id.is_empty() {
    46            state.serialize_entry("messageId", &self.message_id)?;
    47        }
    48        if self.publish_time.is_some() {
    49            state.serialize_entry("publishTime", &self.publish_time)?;
    50        }
    51        if !self.ordering_key.is_empty() {
    52            state.serialize_entry("orderingKey", &self.ordering_key)?;
    53        }
    54        if !self._unknown_fields.is_empty() {
    55            for (key, value) in self._unknown_fields.iter() {
    56                state.serialize_entry(key, &value)?;
    57            }
    58        }
    59        state.end()
    60    }
    61}
    62
    63#[doc(hidden)]
    64impl serde::ser::Serialize for super::PublishRequest {
    65    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    66    where
    67        S: serde::ser::Serializer,
    68    {
    69        use serde::ser::SerializeMap;
    70        #[allow(unused_imports)]
    71        use std::option::Option::Some;
    72        let mut state = serializer.serialize_map(std::option::Option::None)?;
    73        if !self.topic.is_empty() {
    74            state.serialize_entry("topic", &self.topic)?;
    75        }
    76        if !self.messages.is_empty() {
    77            state.serialize_entry("messages", &self.messages)?;
    78        }
    79        if !self._unknown_fields.is_empty() {
    80            for (key, value) in self._unknown_fields.iter() {
    81                state.serialize_entry(key, &value)?;
    82            }
    83        }
    84        state.end()
    85    }
    86}
    87
    88#[doc(hidden)]
    89impl serde::ser::Serialize for super::PublishResponse {
    90    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    91    where
    92        S: serde::ser::Serializer,
    93    {
    94        use serde::ser::SerializeMap;
    95        #[allow(unused_imports)]
    96        use std::option::Option::Some;
    97        let mut state = serializer.serialize_map(std::option::Option::None)?;
    98        if !self.message_ids.is_empty() {
    99            state.serialize_entry("messageIds", &self.message_ids)?;
    100        }
    101        if !self._unknown_fields.is_empty() {
    102            for (key, value) in self._unknown_fields.iter() {
    103                state.serialize_entry(key, &value)?;
    104            }
    105        }
    106        state.end()
    107    }
    108}
    109
    110#[doc(hidden)]
    111impl serde::ser::Serialize for super::ReceivedMessage {
    112    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    113    where
    114        S: serde::ser::Serializer,
    115    {
    116        use serde::ser::SerializeMap;
    117        #[allow(unused_imports)]
    118        use std::option::Option::Some;
    119        let mut state = serializer.serialize_map(std::option::Option::None)?;
    120        if !self.ack_id.is_empty() {
    121            state.serialize_entry("ackId", &self.ack_id)?;
    122        }
    123        if self.message.is_some() {
    124            state.serialize_entry("message", &self.message)?;
    125        }
    126        if !wkt::internal::is_default(&self.delivery_attempt) {
    127            struct __With<'a>(&'a i32);
    128            impl<'a> serde::ser::Serialize for __With<'a> {
    129                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    130                where
    131                    S: serde::ser::Serializer,
    132                {
    133                    serde_with::As::<wkt::internal::I32>::serialize(self.0, serializer)
    134                }
    135            }
    136            state.serialize_entry("deliveryAttempt", &__With(&self.delivery_attempt))?;
    137        }
    138        if !self._unknown_fields.is_empty() {
    139            for (key, value) in self._unknown_fields.iter() {
    140                state.serialize_entry(key, &value)?;
    141            }
    142        }
    143        state.end()
    144    }
    145}
    146
    147#[doc(hidden)]
    148impl serde::ser::Serialize for super::ModifyAckDeadlineRequest {
    149    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    150    where
    151        S: serde::ser::Serializer,
    152    {
    153        use serde::ser::SerializeMap;
    154        #[allow(unused_imports)]
    155        use std::option::Option::Some;
    156        let mut state = serializer.serialize_map(std::option::Option::None)?;
    157        if !self.subscription.is_empty() {
    158            state.serialize_entry("subscription", &self.subscription)?;
    159        }
    160        if !self.ack_ids.is_empty() {
    161            state.serialize_entry("ackIds", &self.ack_ids)?;
    162        }
    163        if !wkt::internal::is_default(&self.ack_deadline_seconds) {
    164            struct __With<'a>(&'a i32);
    165            impl<'a> serde::ser::Serialize for __With<'a> {
    166                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    167                where
    168                    S: serde::ser::Serializer,
    169                {
    170                    serde_with::As::<wkt::internal::I32>::serialize(self.0, serializer)
    171                }
    172            }
    173            state.serialize_entry("ackDeadlineSeconds", &__With(&self.ack_deadline_seconds))?;
    174        }
    175        if !self._unknown_fields.is_empty() {
    176            for (key, value) in self._unknown_fields.iter() {
    177                state.serialize_entry(key, &value)?;
    178            }
    179        }
    180        state.end()
    181    }
    182}
    183
    184#[doc(hidden)]
    185impl serde::ser::Serialize for super::AcknowledgeRequest {
    186    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    187    where
    188        S: serde::ser::Serializer,
    189    {
    190        use serde::ser::SerializeMap;
    191        #[allow(unused_imports)]
    192        use std::option::Option::Some;
    193        let mut state = serializer.serialize_map(std::option::Option::None)?;
    194        if !self.subscription.is_empty() {
    195            state.serialize_entry("subscription", &self.subscription)?;
    196        }
    197        if !self.ack_ids.is_empty() {
    198            state.serialize_entry("ackIds", &self.ack_ids)?;
    199        }
    200        if !self._unknown_fields.is_empty() {
    201            for (key, value) in self._unknown_fields.iter() {
    202                state.serialize_entry(key, &value)?;
    203            }
    204        }
    205        state.end()
    206    }
    207}
    208
    209#[doc(hidden)]
    210impl serde::ser::Serialize for super::StreamingPullRequest {
    211    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    212    where
    213        S: serde::ser::Serializer,
    214    {
    215        use serde::ser::SerializeMap;
    216        #[allow(unused_imports)]
    217        use std::option::Option::Some;
    218        let mut state = serializer.serialize_map(std::option::Option::None)?;
    219        if !self.subscription.is_empty() {
    220            state.serialize_entry("subscription", &self.subscription)?;
    221        }
    222        if !self.ack_ids.is_empty() {
    223            state.serialize_entry("ackIds", &self.ack_ids)?;
    224        }
    225        if !self.modify_deadline_seconds.is_empty() {
    226            struct __With<'a>(&'a std::vec::Vec<i32>);
    227            impl<'a> serde::ser::Serialize for __With<'a> {
    228                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    229                where
    230                    S: serde::ser::Serializer,
    231                {
    232                    serde_with::As::<std::vec::Vec<wkt::internal::I32>>::serialize(
    233                        self.0, serializer,
    234                    )
    235                }
    236            }
    237            state.serialize_entry(
    238                "modifyDeadlineSeconds",
    239                &__With(&self.modify_deadline_seconds),
    240            )?;
    241        }
    242        if !self.modify_deadline_ack_ids.is_empty() {
    243            state.serialize_entry("modifyDeadlineAckIds", &self.modify_deadline_ack_ids)?;
    244        }
    245        if !wkt::internal::is_default(&self.stream_ack_deadline_seconds) {
    246            struct __With<'a>(&'a i32);
    247            impl<'a> serde::ser::Serialize for __With<'a> {
    248                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    249                where
    250                    S: serde::ser::Serializer,
    251                {
    252                    serde_with::As::<wkt::internal::I32>::serialize(self.0, serializer)
    253                }
    254            }
    255            state.serialize_entry(
    256                "streamAckDeadlineSeconds",
    257                &__With(&self.stream_ack_deadline_seconds),
    258            )?;
    259        }
    260        if !self.client_id.is_empty() {
    261            state.serialize_entry("clientId", &self.client_id)?;
    262        }
    263        if !wkt::internal::is_default(&self.max_outstanding_messages) {
    264            struct __With<'a>(&'a i64);
    265            impl<'a> serde::ser::Serialize for __With<'a> {
    266                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    267                where
    268                    S: serde::ser::Serializer,
    269                {
    270                    serde_with::As::<wkt::internal::I64>::serialize(self.0, serializer)
    271                }
    272            }
    273            state.serialize_entry(
    274                "maxOutstandingMessages",
    275                &__With(&self.max_outstanding_messages),
    276            )?;
    277        }
    278        if !wkt::internal::is_default(&self.max_outstanding_bytes) {
    279            struct __With<'a>(&'a i64);
    280            impl<'a> serde::ser::Serialize for __With<'a> {
    281                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    282                where
    283                    S: serde::ser::Serializer,
    284                {
    285                    serde_with::As::<wkt::internal::I64>::serialize(self.0, serializer)
    286                }
    287            }
    288            state.serialize_entry("maxOutstandingBytes", &__With(&self.max_outstanding_bytes))?;
    289        }
    290        if !wkt::internal::is_default(&self.protocol_version) {
    291            struct __With<'a>(&'a i64);
    292            impl<'a> serde::ser::Serialize for __With<'a> {
    293                fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    294                where
    295                    S: serde::ser::Serializer,
    296                {
    297                    serde_with::As::<wkt::internal::I64>::serialize(self.0, serializer)
    298                }
    299            }
    300            state.serialize_entry("protocolVersion", &__With(&self.protocol_version))?;
    301        }
    302        if !self._unknown_fields.is_empty() {
    303            for (key, value) in self._unknown_fields.iter() {
    304                state.serialize_entry(key, &value)?;
    305            }
    306        }
    307        state.end()
    308    }
    309}
    310
    311#[doc(hidden)]
    312impl serde::ser::Serialize for super::StreamingPullResponse {
    313    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    314    where
    315        S: serde::ser::Serializer,
    316    {
    317        use serde::ser::SerializeMap;
    318        #[allow(unused_imports)]
    319        use std::option::Option::Some;
    320        let mut state = serializer.serialize_map(std::option::Option::None)?;
    321        if !self.received_messages.is_empty() {
    322            state.serialize_entry("receivedMessages", &self.received_messages)?;
    323        }
    324        if self.acknowledge_confirmation.is_some() {
    325            state.serialize_entry("acknowledgeConfirmation", &self.acknowledge_confirmation)?;
    326        }
    327        if self.modify_ack_deadline_confirmation.is_some() {
    328            state.serialize_entry(
    329                "modifyAckDeadlineConfirmation",
    330                &self.modify_ack_deadline_confirmation,
    331            )?;
    332        }
    333        if self.subscription_properties.is_some() {
    334            state.serialize_entry("subscriptionProperties", &self.subscription_properties)?;
    335        }
    336        if !self._unknown_fields.is_empty() {
    337            for (key, value) in self._unknown_fields.iter() {
    338                state.serialize_entry(key, &value)?;
    339            }
    340        }
    341        state.end()
    342    }
    343}
    344
    345#[doc(hidden)]
    346impl serde::ser::Serialize for super::streaming_pull_response::AcknowledgeConfirmation {
    347    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    348    where
    349        S: serde::ser::Serializer,
    350    {
    351        use serde::ser::SerializeMap;
    352        #[allow(unused_imports)]
    353        use std::option::Option::Some;
    354        let mut state = serializer.serialize_map(std::option::Option::None)?;
    355        if !self.ack_ids.is_empty() {
    356            state.serialize_entry("ackIds", &self.ack_ids)?;
    357        }
    358        if !self.invalid_ack_ids.is_empty() {
    359            state.serialize_entry("invalidAckIds", &self.invalid_ack_ids)?;
    360        }
    361        if !self.unordered_ack_ids.is_empty() {
    362            state.serialize_entry("unorderedAckIds", &self.unordered_ack_ids)?;
    363        }
    364        if !self.temporary_failed_ack_ids.is_empty() {
    365            state.serialize_entry("temporaryFailedAckIds", &self.temporary_failed_ack_ids)?;
    366        }
    367        if !self._unknown_fields.is_empty() {
    368            for (key, value) in self._unknown_fields.iter() {
    369                state.serialize_entry(key, &value)?;
    370            }
    371        }
    372        state.end()
    373    }
    374}
    375
    376#[doc(hidden)]
    377impl serde::ser::Serialize for super::streaming_pull_response::ModifyAckDeadlineConfirmation {
    378    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    379    where
    380        S: serde::ser::Serializer,
    381    {
    382        use serde::ser::SerializeMap;
    383        #[allow(unused_imports)]
    384        use std::option::Option::Some;
    385        let mut state = serializer.serialize_map(std::option::Option::None)?;
    386        if !self.ack_ids.is_empty() {
    387            state.serialize_entry("ackIds", &self.ack_ids)?;
    388        }
    389        if !self.invalid_ack_ids.is_empty() {
    390            state.serialize_entry("invalidAckIds", &self.invalid_ack_ids)?;
    391        }
    392        if !self.temporary_failed_ack_ids.is_empty() {
    393            state.serialize_entry("temporaryFailedAckIds", &self.temporary_failed_ack_ids)?;
    394        }
    395        if !self._unknown_fields.is_empty() {
    396            for (key, value) in self._unknown_fields.iter() {
    397                state.serialize_entry(key, &value)?;
    398            }
    399        }
    400        state.end()
    401    }
    402}
    403
    404#[doc(hidden)]
    405impl serde::ser::Serialize for super::streaming_pull_response::SubscriptionProperties {
    406    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    407    where
    408        S: serde::ser::Serializer,
    409    {
    410        use serde::ser::SerializeMap;
    411        #[allow(unused_imports)]
    412        use std::option::Option::Some;
    413        let mut state = serializer.serialize_map(std::option::Option::None)?;
    414        if !wkt::internal::is_default(&self.exactly_once_delivery_enabled) {
    415            state.serialize_entry(
    416                "exactlyOnceDeliveryEnabled",
    417                &self.exactly_once_delivery_enabled,
    418            )?;
    419        }
    420        if !wkt::internal::is_default(&self.message_ordering_enabled) {
    421            state.serialize_entry("messageOrderingEnabled", &self.message_ordering_enabled)?;
    422        }
    423        if !self._unknown_fields.is_empty() {
    424            for (key, value) in self._unknown_fields.iter() {
    425                state.serialize_entry(key, &value)?;
    426            }
    427        }
    428        state.end()
    429    }
    430}