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