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