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