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_i32, get_i64, get_i8, put_i32, put_i64, put_i8};
6use crate::primitives::string_bytes::{
7    compact_string_len, get_compact_string_owned, get_string_owned,
8    put_compact_string, put_string, string_len,
9};
10use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
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 { version >= FLEXIBLE_MIN }
20
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct ListOffsetsRequest {
23    pub replica_id: i32,
24    pub isolation_level: i8,
25    pub topics: Vec<ListOffsetsTopic>,
26    pub timeout_ms: i32,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29
30impl Encode for ListOffsetsRequest {
31    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
32        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
33            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
34        }
35        let flex = is_flexible(version);
36        if version >= 0 { put_i32(buf, self.replica_id) }
37        if version >= 2 { put_i8(buf, self.isolation_level) }
38        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
39        if version >= 10 { put_i32(buf, self.timeout_ms) }
40        if flex {
41            let tagged = WriteTaggedFields::new();
42            tagged.write(buf, &self.unknown_tagged_fields);
43        }
44        Ok(())
45    }
46    fn encoded_len(&self, version: i16) -> usize {
47        let flex = is_flexible(version);
48        let mut n: usize = 0;
49        if version >= 0 { n += 4; }
50        if version >= 2 { n += 1; }
51        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topics).len(), flex); let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
52        if version >= 10 { n += 4; }
53        if flex {
54            let known_pairs: Vec<(u32, usize)> = Vec::new();
55            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
56        }
57        n
58    }
59}
60
61impl<'de> Decode<'de> for ListOffsetsRequest {
62    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
63        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
64            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
65        }
66        let flex = is_flexible(version);
67        let mut out = Self::default();
68        if version >= 0 { out.replica_id = get_i32(buf)?; }
69        if version >= 2 { out.isolation_level = get_i8(buf)?; }
70        if version >= 0 { out.topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(ListOffsetsTopic::decode(buf, version)?); } v }; }
71        if version >= 10 { out.timeout_ms = get_i32(buf)?; }
72        if flex {
73            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
74                Ok(false)
75            })?;
76        }
77        Ok(out)
78    }
79}
80
81#[derive(Debug, Clone, PartialEq, Eq, Default)]
82pub struct ListOffsetsTopic {
83    pub name: String,
84    pub partitions: Vec<ListOffsetsPartition>,
85    pub unknown_tagged_fields: UnknownTaggedFields,
86}
87
88impl Encode for ListOffsetsTopic {
89    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
90        let flex = version >= 6;
91        if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
92        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
93        if flex {
94            let tagged = WriteTaggedFields::new();
95            tagged.write(buf, &self.unknown_tagged_fields);
96        }
97        Ok(())
98    }
99    fn encoded_len(&self, version: i16) -> usize {
100        let flex = version >= 6;
101        let mut n: usize = 0;
102        if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
103        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex); let body: usize = (self.partitions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
104        if flex {
105            let known_pairs: Vec<(u32, usize)> = Vec::new();
106            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
107        }
108        n
109    }
110}
111
112impl<'de> Decode<'de> for ListOffsetsTopic {
113    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
114        let flex = version >= 6;
115        let mut out = Self::default();
116        if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
117        if version >= 0 { out.partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(ListOffsetsPartition::decode(buf, version)?); } v }; }
118        if flex {
119            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
120                Ok(false)
121            })?;
122        }
123        Ok(out)
124    }
125}
126
127#[derive(Debug, Clone, PartialEq, Eq)]
128pub struct ListOffsetsPartition {
129    pub partition_index: i32,
130    pub current_leader_epoch: i32,
131    pub timestamp: i64,
132    pub unknown_tagged_fields: UnknownTaggedFields,
133}
134
135impl Default for ListOffsetsPartition {
136    fn default() -> Self {
137        Self {
138            partition_index: 0i32,
139            current_leader_epoch: -1i32,
140            timestamp: 0i64,
141            unknown_tagged_fields: Default::default(),
142        }
143    }
144}
145
146impl Encode for ListOffsetsPartition {
147    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
148        let flex = version >= 6;
149        if version >= 0 { put_i32(buf, self.partition_index) }
150        if version >= 4 { put_i32(buf, self.current_leader_epoch) }
151        if version >= 0 { put_i64(buf, self.timestamp) }
152        if flex {
153            let tagged = WriteTaggedFields::new();
154            tagged.write(buf, &self.unknown_tagged_fields);
155        }
156        Ok(())
157    }
158    fn encoded_len(&self, version: i16) -> usize {
159        let flex = version >= 6;
160        let mut n: usize = 0;
161        if version >= 0 { n += 4; }
162        if version >= 4 { n += 4; }
163        if version >= 0 { n += 8; }
164        if flex {
165            let known_pairs: Vec<(u32, usize)> = Vec::new();
166            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
167        }
168        n
169    }
170}
171
172impl<'de> Decode<'de> for ListOffsetsPartition {
173    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
174        let flex = version >= 6;
175        let mut out = Self::default();
176        if version >= 0 { out.partition_index = get_i32(buf)?; }
177        if version >= 4 { out.current_leader_epoch = get_i32(buf)?; }
178        if version >= 0 { out.timestamp = get_i64(buf)?; }
179        if flex {
180            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
181                Ok(false)
182            })?;
183        }
184        Ok(out)
185    }
186}
187
188/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
189/// Only includes fields valid for the given version.
190#[must_use]
191#[allow(unused_comparisons)]
192pub fn default_json(version: i16) -> ::serde_json::Value {
193    let mut obj = ::serde_json::Map::new();
194    obj.insert("replicaId".to_string(), ::serde_json::json!(0));
195    if version >= 2 {
196        obj.insert("isolationLevel".to_string(), ::serde_json::json!(0));
197    }
198    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
199    if version >= 10 {
200        obj.insert("timeoutMs".to_string(), ::serde_json::json!(0));
201    }
202    ::serde_json::Value::Object(obj)
203}
204
205impl crate::ProtocolRequest for ListOffsetsRequest {
206    const API_KEY: i16 = API_KEY;
207    const MIN_VERSION: i16 = MIN_VERSION;
208    const MAX_VERSION: i16 = MAX_VERSION;
209    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
210    type Response = super::list_offsets_response::ListOffsetsResponse;
211}