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