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