Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
InitializeShareGroupStateResponse.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
3use crate::primitives::string_bytes::{
4    compact_nullable_string_len, nullable_string_len, put_compact_nullable_string,
5    put_nullable_string,
6};
7use crate::primitives::string_bytes_borrowed::{
8    get_compact_nullable_string_borrowed, get_nullable_string_borrowed,
9};
10use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
11use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
12use bytes::BufMut;
13pub const API_KEY: i16 = 83;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 0;
16pub const FLEXIBLE_MIN: i16 = 0;
17#[inline]
18fn is_flexible(version: i16) -> bool {
19    version >= FLEXIBLE_MIN
20}
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct InitializeShareGroupStateResponse<'a> {
23    pub results: Vec<InitializeStateResult<'a>>,
24    pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl InitializeShareGroupStateResponse<'_> {
27    pub fn to_owned(
28        &self,
29    ) -> crate::owned::initialize_share_group_state_response::InitializeShareGroupStateResponse
30    {
31        crate::owned::initialize_share_group_state_response::InitializeShareGroupStateResponse {
32            results: (self.results)
33                .iter()
34                .map(InitializeStateResult::to_owned)
35                .collect(),
36            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
37        }
38    }
39}
40impl Encode for InitializeShareGroupStateResponse<'_> {
41    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
42        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
43            return Err(ProtocolError::UnsupportedVersion {
44                api_key: API_KEY,
45                version,
46            });
47        }
48        let flex = is_flexible(version);
49        if version >= 0 {
50            {
51                crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
52                for it in &self.results {
53                    it.encode(buf, version)?;
54                }
55            }
56        }
57        if flex {
58            let tagged = WriteTaggedFields::new();
59            tagged.write(buf, &self.unknown_tagged_fields);
60        }
61        Ok(())
62    }
63    fn encoded_len(&self, version: i16) -> usize {
64        let flex = is_flexible(version);
65        let mut n: usize = 0;
66        if version >= 0 {
67            n += {
68                let prefix =
69                    crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
70                let body: usize = (self.results)
71                    .iter()
72                    .map(|it| it.encoded_len(version))
73                    .sum();
74                prefix + body
75            };
76        }
77        if flex {
78            let known_pairs: Vec<(u32, usize)> = Vec::new();
79            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
80        }
81        n
82    }
83}
84impl<'de> DecodeBorrow<'de> for InitializeShareGroupStateResponse<'de> {
85    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
86        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
87            return Err(ProtocolError::UnsupportedVersion {
88                api_key: API_KEY,
89                version,
90            });
91        }
92        let flex = is_flexible(version);
93        let mut out = Self::default();
94        if version >= 0 {
95            out.results = {
96                let n = crate::primitives::array::get_array_len(buf, flex)?;
97                let mut v = Vec::with_capacity(n);
98                for _ in 0..n {
99                    v.push(InitializeStateResult::decode_borrow(buf, version)?);
100                }
101                v
102            };
103        }
104        if flex {
105            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
106        }
107        Ok(out)
108    }
109}
110#[cfg(test)]
111impl InitializeShareGroupStateResponse<'_> {
112    #[must_use]
113    pub fn populated(version: i16) -> Self {
114        let mut m = Self::default();
115        if version >= 0 {
116            m.results = vec![InitializeStateResult::populated(version)];
117        }
118        m
119    }
120}
121#[derive(Debug, Clone, PartialEq, Eq, Default)]
122pub struct InitializeStateResult<'a> {
123    pub topic_id: crate::primitives::uuid::Uuid,
124    pub partitions: Vec<PartitionResult<'a>>,
125    pub unknown_tagged_fields: UnknownTaggedFields,
126}
127impl InitializeStateResult<'_> {
128    pub fn to_owned(
129        &self,
130    ) -> crate::owned::initialize_share_group_state_response::InitializeStateResult {
131        crate::owned::initialize_share_group_state_response::InitializeStateResult {
132            topic_id: (self.topic_id),
133            partitions: (self.partitions)
134                .iter()
135                .map(PartitionResult::to_owned)
136                .collect(),
137            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
138        }
139    }
140}
141impl Encode for InitializeStateResult<'_> {
142    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
143        let flex = version >= 0;
144        if version >= 0 {
145            crate::primitives::uuid::put_uuid(buf, self.topic_id);
146        }
147        if version >= 0 {
148            {
149                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
150                for it in &self.partitions {
151                    it.encode(buf, version)?;
152                }
153            }
154        }
155        if flex {
156            let tagged = WriteTaggedFields::new();
157            tagged.write(buf, &self.unknown_tagged_fields);
158        }
159        Ok(())
160    }
161    fn encoded_len(&self, version: i16) -> usize {
162        let flex = version >= 0;
163        let mut n: usize = 0;
164        if version >= 0 {
165            n += 16;
166        }
167        if version >= 0 {
168            n += {
169                let prefix =
170                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
171                let body: usize = (self.partitions)
172                    .iter()
173                    .map(|it| it.encoded_len(version))
174                    .sum();
175                prefix + body
176            };
177        }
178        if flex {
179            let known_pairs: Vec<(u32, usize)> = Vec::new();
180            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
181        }
182        n
183    }
184}
185impl<'de> DecodeBorrow<'de> for InitializeStateResult<'de> {
186    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
187        let flex = version >= 0;
188        let mut out = Self::default();
189        if version >= 0 {
190            out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
191        }
192        if version >= 0 {
193            out.partitions = {
194                let n = crate::primitives::array::get_array_len(buf, flex)?;
195                let mut v = Vec::with_capacity(n);
196                for _ in 0..n {
197                    v.push(PartitionResult::decode_borrow(buf, version)?);
198                }
199                v
200            };
201        }
202        if flex {
203            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
204        }
205        Ok(out)
206    }
207}
208#[cfg(test)]
209impl InitializeStateResult<'_> {
210    #[must_use]
211    pub fn populated(version: i16) -> Self {
212        let mut m = Self::default();
213        if version >= 0 {
214            m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
215        }
216        if version >= 0 {
217            m.partitions = vec![PartitionResult::populated(version)];
218        }
219        m
220    }
221}
222#[derive(Debug, Clone, PartialEq, Eq, Default)]
223pub struct PartitionResult<'a> {
224    pub partition: i32,
225    pub error_code: i16,
226    pub error_message: Option<&'a str>,
227    pub unknown_tagged_fields: UnknownTaggedFields,
228}
229impl PartitionResult<'_> {
230    pub fn to_owned(&self) -> crate::owned::initialize_share_group_state_response::PartitionResult {
231        crate::owned::initialize_share_group_state_response::PartitionResult {
232            partition: (self.partition),
233            error_code: (self.error_code),
234            error_message: (self.error_message).map(std::string::ToString::to_string),
235            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
236        }
237    }
238}
239impl Encode for PartitionResult<'_> {
240    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
241        let flex = version >= 0;
242        if version >= 0 {
243            put_i32(buf, self.partition);
244        }
245        if version >= 0 {
246            put_i16(buf, self.error_code);
247        }
248        if version >= 0 {
249            if flex {
250                put_compact_nullable_string(buf, self.error_message);
251            } else {
252                put_nullable_string(buf, self.error_message);
253            }
254        }
255        if flex {
256            let tagged = WriteTaggedFields::new();
257            tagged.write(buf, &self.unknown_tagged_fields);
258        }
259        Ok(())
260    }
261    fn encoded_len(&self, version: i16) -> usize {
262        let flex = version >= 0;
263        let mut n: usize = 0;
264        if version >= 0 {
265            n += 4;
266        }
267        if version >= 0 {
268            n += 2;
269        }
270        if version >= 0 {
271            n += if flex {
272                compact_nullable_string_len(self.error_message)
273            } else {
274                nullable_string_len(self.error_message)
275            };
276        }
277        if flex {
278            let known_pairs: Vec<(u32, usize)> = Vec::new();
279            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
280        }
281        n
282    }
283}
284impl<'de> DecodeBorrow<'de> for PartitionResult<'de> {
285    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
286        let flex = version >= 0;
287        let mut out = Self::default();
288        if version >= 0 {
289            out.partition = get_i32(buf)?;
290        }
291        if version >= 0 {
292            out.error_code = get_i16(buf)?;
293        }
294        if version >= 0 {
295            out.error_message = if flex {
296                get_compact_nullable_string_borrowed(buf)?
297            } else {
298                get_nullable_string_borrowed(buf)?
299            };
300        }
301        if flex {
302            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
303        }
304        Ok(out)
305    }
306}
307#[cfg(test)]
308impl PartitionResult<'_> {
309    #[must_use]
310    pub fn populated(version: i16) -> Self {
311        let mut m = Self::default();
312        if version >= 0 {
313            m.partition = 1i32;
314        }
315        if version >= 0 {
316            m.error_code = 1i16;
317        }
318        if version >= 0 {
319            m.error_message = Some("x");
320        }
321        m
322    }
323}