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