Skip to main content

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