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