Skip to main content

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

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