Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ListOffsetsResponse.owned.rs

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