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