Skip to main content

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

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