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