Skip to main content

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