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