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