Skip to main content

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

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