Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use crate::primitives::fixed::{get_i32, get_i64, put_i32, put_i64};
3use crate::primitives::string_bytes::{
4    compact_string_len, put_compact_string, put_string, string_len,
5};
6use crate::primitives::string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed};
7use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
8use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
9use bytes::BufMut;
10pub const API_KEY: i16 = 83;
11pub const MIN_VERSION: i16 = 0;
12pub const MAX_VERSION: i16 = 0;
13pub const FLEXIBLE_MIN: i16 = 0;
14#[inline]
15fn is_flexible(version: i16) -> bool {
16    version >= FLEXIBLE_MIN
17}
18#[derive(Debug, Clone, PartialEq, Eq, Default)]
19pub struct InitializeShareGroupStateRequest<'a> {
20    pub group_id: &'a str,
21    pub topics: Vec<InitializeStateData>,
22    pub unknown_tagged_fields: UnknownTaggedFields,
23}
24impl InitializeShareGroupStateRequest<'_> {
25    pub fn to_owned(
26        &self,
27    ) -> crate::owned::initialize_share_group_state_request::InitializeShareGroupStateRequest {
28        crate::owned::initialize_share_group_state_request::InitializeShareGroupStateRequest {
29            group_id: (self.group_id).to_string(),
30            topics: (self.topics)
31                .iter()
32                .map(InitializeStateData::to_owned)
33                .collect(),
34            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
35        }
36    }
37}
38impl Encode for InitializeShareGroupStateRequest<'_> {
39    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
40        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
41            return Err(ProtocolError::UnsupportedVersion {
42                api_key: API_KEY,
43                version,
44            });
45        }
46        let flex = is_flexible(version);
47        if version >= 0 {
48            if flex {
49                put_compact_string(buf, self.group_id);
50            } else {
51                put_string(buf, self.group_id);
52            }
53        }
54        if version >= 0 {
55            {
56                crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
57                for it in &self.topics {
58                    it.encode(buf, version)?;
59                }
60            }
61        }
62        if flex {
63            let tagged = WriteTaggedFields::new();
64            tagged.write(buf, &self.unknown_tagged_fields);
65        }
66        Ok(())
67    }
68    fn encoded_len(&self, version: i16) -> usize {
69        let flex = is_flexible(version);
70        let mut n: usize = 0;
71        if version >= 0 {
72            n += if flex {
73                compact_string_len(self.group_id)
74            } else {
75                string_len(self.group_id)
76            };
77        }
78        if version >= 0 {
79            n += {
80                let prefix =
81                    crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
82                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
83                prefix + body
84            };
85        }
86        if flex {
87            let known_pairs: Vec<(u32, usize)> = Vec::new();
88            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
89        }
90        n
91    }
92}
93impl<'de> DecodeBorrow<'de> for InitializeShareGroupStateRequest<'de> {
94    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
95        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
96            return Err(ProtocolError::UnsupportedVersion {
97                api_key: API_KEY,
98                version,
99            });
100        }
101        let flex = is_flexible(version);
102        let mut out = Self::default();
103        if version >= 0 {
104            out.group_id = if flex {
105                get_compact_string_borrowed(buf)?
106            } else {
107                get_string_borrowed(buf)?
108            };
109        }
110        if version >= 0 {
111            out.topics = {
112                let n = crate::primitives::array::get_array_len(buf, flex)?;
113                let mut v = Vec::with_capacity(n);
114                for _ in 0..n {
115                    v.push(InitializeStateData::decode_borrow(buf, version)?);
116                }
117                v
118            };
119        }
120        if flex {
121            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
122        }
123        Ok(out)
124    }
125}
126#[cfg(test)]
127impl InitializeShareGroupStateRequest<'_> {
128    #[must_use]
129    pub fn populated(version: i16) -> Self {
130        let mut m = Self::default();
131        if version >= 0 {
132            m.group_id = "x";
133        }
134        if version >= 0 {
135            m.topics = vec![InitializeStateData::populated(version)];
136        }
137        m
138    }
139}
140#[derive(Debug, Clone, PartialEq, Eq, Default)]
141pub struct InitializeStateData {
142    pub topic_id: crate::primitives::uuid::Uuid,
143    pub partitions: Vec<PartitionData>,
144    pub unknown_tagged_fields: UnknownTaggedFields,
145}
146impl InitializeStateData {
147    pub fn to_owned(
148        &self,
149    ) -> crate::owned::initialize_share_group_state_request::InitializeStateData {
150        crate::owned::initialize_share_group_state_request::InitializeStateData {
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 InitializeStateData {
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 InitializeStateData {
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 InitializeStateData {
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 state_epoch: i32,
245    pub start_offset: i64,
246    pub unknown_tagged_fields: UnknownTaggedFields,
247}
248impl PartitionData {
249    pub fn to_owned(&self) -> crate::owned::initialize_share_group_state_request::PartitionData {
250        crate::owned::initialize_share_group_state_request::PartitionData {
251            partition: (self.partition),
252            state_epoch: (self.state_epoch),
253            start_offset: (self.start_offset),
254            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
255        }
256    }
257}
258impl Encode for PartitionData {
259    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
260        let flex = version >= 0;
261        if version >= 0 {
262            put_i32(buf, self.partition);
263        }
264        if version >= 0 {
265            put_i32(buf, self.state_epoch);
266        }
267        if version >= 0 {
268            put_i64(buf, self.start_offset);
269        }
270        if flex {
271            let tagged = WriteTaggedFields::new();
272            tagged.write(buf, &self.unknown_tagged_fields);
273        }
274        Ok(())
275    }
276    fn encoded_len(&self, version: i16) -> usize {
277        let flex = version >= 0;
278        let mut n: usize = 0;
279        if version >= 0 {
280            n += 4;
281        }
282        if version >= 0 {
283            n += 4;
284        }
285        if version >= 0 {
286            n += 8;
287        }
288        if flex {
289            let known_pairs: Vec<(u32, usize)> = Vec::new();
290            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
291        }
292        n
293    }
294}
295impl<'de> DecodeBorrow<'de> for PartitionData {
296    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
297        let flex = version >= 0;
298        let mut out = Self::default();
299        if version >= 0 {
300            out.partition = get_i32(buf)?;
301        }
302        if version >= 0 {
303            out.state_epoch = get_i32(buf)?;
304        }
305        if version >= 0 {
306            out.start_offset = get_i64(buf)?;
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 PartitionData {
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.state_epoch = 1i32;
324        }
325        if version >= 0 {
326            m.start_offset = 1i64;
327        }
328        m
329    }
330}