Skip to main content

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