Skip to main content

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

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