krabka_protocol/opt/rustwide/workdir/generated/
ListOffsetsResponse.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 = 2;
17pub const MIN_VERSION: i16 = 1;
18pub const MAX_VERSION: i16 = 11;
19pub const FLEXIBLE_MIN: i16 = 6;
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 ListOffsetsResponse {
27 pub throttle_time_ms: i32,
28 pub topics: Vec<ListOffsetsTopicResponse>,
29 pub unknown_tagged_fields: UnknownTaggedFields,
30}
31impl Encode for ListOffsetsResponse {
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 ListOffsetsResponse {
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(ListOffsetsTopicResponse::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 ListOffsetsResponse {
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![ListOffsetsTopicResponse::populated(version)];
117 }
118 m
119 }
120}
121#[derive(Debug, Clone, PartialEq, Eq, Default)]
122pub struct ListOffsetsTopicResponse {
123 pub name: String,
124 pub partitions: Vec<ListOffsetsPartitionResponse>,
125 pub unknown_tagged_fields: UnknownTaggedFields,
126}
127impl Encode for ListOffsetsTopicResponse {
128 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
129 let flex = version >= 6;
130 if version >= 0 {
131 if flex {
132 let () = put_compact_string(buf, &self.name);
133 } else {
134 let () = put_string(buf, &self.name);
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 >= 6;
153 let mut n: usize = 0;
154 if version >= 0 {
155 n += if flex {
156 compact_string_len(&self.name)
157 } else {
158 string_len(&self.name)
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 ListOffsetsTopicResponse {
180 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
181 let flex = version >= 6;
182 let mut out = Self::default();
183 if version >= 0 {
184 out.name = 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(ListOffsetsPartitionResponse::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 ListOffsetsTopicResponse {
208 #[must_use]
209 pub fn populated(version: i16) -> Self {
210 let mut m = Self::default();
211 if version >= 0 {
212 m.name = "x".to_string();
213 }
214 if version >= 0 {
215 m.partitions = vec![ListOffsetsPartitionResponse::populated(version)];
216 }
217 m
218 }
219}
220#[derive(Debug, Clone, PartialEq, Eq)]
221pub struct ListOffsetsPartitionResponse {
222 pub partition_index: i32,
223 pub error_code: i16,
224 pub timestamp: i64,
225 pub offset: i64,
226 pub leader_epoch: i32,
227 pub unknown_tagged_fields: UnknownTaggedFields,
228}
229impl Default for ListOffsetsPartitionResponse {
230 fn default() -> Self {
231 Self {
232 partition_index: 0i32,
233 error_code: 0i16,
234 timestamp: -1i64,
235 offset: -1i64,
236 leader_epoch: -1i32,
237 unknown_tagged_fields: UnknownTaggedFields::default(),
238 }
239 }
240}
241impl Encode for ListOffsetsPartitionResponse {
242 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
243 let flex = version >= 6;
244 if version >= 0 {
245 put_i32(buf, self.partition_index);
246 }
247 if version >= 0 {
248 put_i16(buf, self.error_code);
249 }
250 if version >= 1 {
251 put_i64(buf, self.timestamp);
252 }
253 if version >= 1 {
254 put_i64(buf, self.offset);
255 }
256 if version >= 4 {
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 >= 6;
267 let mut n: usize = 0;
268 if version >= 0 {
269 n += 4;
270 }
271 if version >= 0 {
272 n += 2;
273 }
274 if version >= 1 {
275 n += 8;
276 }
277 if version >= 1 {
278 n += 8;
279 }
280 if version >= 4 {
281 n += 4;
282 }
283 if flex {
284 let known_pairs: Vec<(u32, usize)> = Vec::new();
285 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
286 }
287 n
288 }
289}
290impl Decode<'_> for ListOffsetsPartitionResponse {
291 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
292 let flex = version >= 6;
293 let mut out = Self::default();
294 if version >= 0 {
295 out.partition_index = get_i32(buf)?;
296 }
297 if version >= 0 {
298 out.error_code = get_i16(buf)?;
299 }
300 if version >= 1 {
301 out.timestamp = get_i64(buf)?;
302 }
303 if version >= 1 {
304 out.offset = get_i64(buf)?;
305 }
306 if version >= 4 {
307 out.leader_epoch = get_i32(buf)?;
308 }
309 if flex {
310 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
311 }
312 Ok(out)
313 }
314}
315#[cfg(test)]
316impl ListOffsetsPartitionResponse {
317 #[must_use]
318 pub fn populated(version: i16) -> Self {
319 let mut m = Self::default();
320 if version >= 0 {
321 m.partition_index = 1i32;
322 }
323 if version >= 0 {
324 m.error_code = 1i16;
325 }
326 if version >= 1 {
327 m.timestamp = 1i64;
328 }
329 if version >= 1 {
330 m.offset = 1i64;
331 }
332 if version >= 4 {
333 m.leader_epoch = 1i32;
334 }
335 m
336 }
337}
338#[must_use]
341#[allow(unused_comparisons)]
342pub fn default_json(version: i16) -> ::serde_json::Value {
343 let mut obj = ::serde_json::Map::new();
344 if version >= 2 {
345 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
346 }
347 obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
348 ::serde_json::Value::Object(obj)
349}