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