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