Skip to main content

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