Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
StreamsGroupTopologyDescriptionUpdateRequest.borrowed.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use bytes::BufMut;
3
4use crate::{
5    DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6    owned::streams_group_topology_description_update_request,
7    primitives::{
8        fixed::{get_i32, put_i32},
9        string_bytes::{compact_string_len, put_compact_string, put_string, string_len},
10        string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed},
11    },
12    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
13};
14pub const API_KEY: i16 = 93;
15pub const MIN_VERSION: i16 = 0;
16pub const MAX_VERSION: i16 = 0;
17pub const LATEST_STABLE_VERSION: i16 = 0;
18pub const FLEXIBLE_MIN: i16 = 0;
19#[inline]
20#[must_use]
21pub fn is_flexible(version: i16) -> bool {
22    version >= FLEXIBLE_MIN
23}
24#[derive(Debug, Clone, PartialEq, Eq, Default)]
25pub struct StreamsGroupTopologyDescriptionUpdateRequest<'a> {
26    pub group_id: &'a str,
27    pub member_id: &'a str,
28    pub topology_epoch: i32,
29    pub topology_description: super::common::streams_group_topology_description_update_request::topology_description::TopologyDescription<'a>,
30    pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl StreamsGroupTopologyDescriptionUpdateRequest<'_> {
33    #[must_use]
34    pub fn to_owned(&self) -> streams_group_topology_description_update_request::StreamsGroupTopologyDescriptionUpdateRequest{
35        streams_group_topology_description_update_request::StreamsGroupTopologyDescriptionUpdateRequest {
36            group_id: (self.group_id).to_owned(),
37            member_id: (self.member_id).to_owned(),
38            topology_epoch: (self.topology_epoch),
39            topology_description: (self.topology_description).to_owned(),
40            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
41        }
42    }
43}
44impl Encode for StreamsGroupTopologyDescriptionUpdateRequest<'_> {
45    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
46        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
47            return Err(ProtocolError::UnsupportedVersion {
48                api_key: API_KEY,
49                version,
50            });
51        }
52        let flex = is_flexible(version);
53        if version >= 0 {
54            if flex {
55                put_compact_string(buf, self.group_id)?;
56            } else {
57                put_string(buf, self.group_id)?;
58            }
59        }
60        if version >= 0 {
61            if flex {
62                put_compact_string(buf, self.member_id)?;
63            } else {
64                put_string(buf, self.member_id)?;
65            }
66        }
67        if version >= 0 {
68            put_i32(buf, self.topology_epoch);
69        }
70        if version >= 0 {
71            self.topology_description.encode(buf, version)?;
72        }
73        if flex {
74            let tagged = WriteTaggedFields::new();
75            tagged.write(buf, &self.unknown_tagged_fields)?;
76        }
77        Ok(())
78    }
79    fn encoded_len(&self, version: i16) -> usize {
80        let flex = is_flexible(version);
81        let mut n: usize = 0;
82        if version >= 0 {
83            n += if flex {
84                compact_string_len(self.group_id)
85            } else {
86                string_len(self.group_id)
87            };
88        }
89        if version >= 0 {
90            n += if flex {
91                compact_string_len(self.member_id)
92            } else {
93                string_len(self.member_id)
94            };
95        }
96        if version >= 0 {
97            n += 4;
98        }
99        if version >= 0 {
100            n += self.topology_description.encoded_len(version);
101        }
102        if flex {
103            let known_pairs: Vec<(u32, usize)> = Vec::new();
104            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
105        }
106        n
107    }
108}
109impl<'de> DecodeBorrow<'de> for StreamsGroupTopologyDescriptionUpdateRequest<'de> {
110    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
111        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
112            return Err(ProtocolError::UnsupportedVersion {
113                api_key: API_KEY,
114                version,
115            });
116        }
117        let flex = is_flexible(version);
118        let mut out = Self::default();
119        if version >= 0 {
120            out.group_id = if flex {
121                get_compact_string_borrowed(buf)?
122            } else {
123                get_string_borrowed(buf)?
124            };
125        }
126        if version >= 0 {
127            out.member_id = if flex {
128                get_compact_string_borrowed(buf)?
129            } else {
130                get_string_borrowed(buf)?
131            };
132        }
133        if version >= 0 {
134            out.topology_epoch = get_i32(buf)?;
135        }
136        if version >= 0 {
137            out.topology_description = super::common::streams_group_topology_description_update_request::topology_description::TopologyDescription::decode_borrow(buf, version)?;
138        }
139        if flex {
140            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
141        }
142        Ok(out)
143    }
144}
145#[cfg(test)]
146impl StreamsGroupTopologyDescriptionUpdateRequest<'_> {
147    #[must_use]
148    pub fn populated(version: i16) -> Self {
149        let mut m = Self::default();
150        if version >= 0 {
151            m.group_id = "x";
152        }
153        if version >= 0 {
154            m.member_id = "x";
155        }
156        if version >= 0 {
157            m.topology_epoch = 1i32;
158        }
159        if version >= 0 {
160            m.topology_description = super::common::streams_group_topology_description_update_request::topology_description::TopologyDescription::populated(version);
161        }
162        m
163    }
164}