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