Skip to main content

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

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