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