krabka_protocol/opt/rustwide/workdir/generated/
ReadShareGroupStateResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 fixed::{get_i8, get_i16, get_i32, get_i64, put_i8, put_i16, put_i32, put_i64},
9 string_bytes::{
10 compact_nullable_string_len, get_compact_nullable_string_owned,
11 get_nullable_string_owned, nullable_string_len, put_compact_nullable_string,
12 put_nullable_string,
13 },
14 },
15 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
16};
17pub const API_KEY: i16 = 84;
18pub const MIN_VERSION: i16 = 0;
19pub const MAX_VERSION: i16 = 0;
20pub const FLEXIBLE_MIN: i16 = 0;
21#[inline]
22#[must_use]
23pub fn is_flexible(version: i16) -> bool {
24 version >= FLEXIBLE_MIN
25}
26#[derive(Debug, Clone, PartialEq, Eq, Default)]
27pub struct ReadShareGroupStateResponse {
28 pub results: Vec<ReadStateResult>,
29 pub unknown_tagged_fields: UnknownTaggedFields,
30}
31impl Encode for ReadShareGroupStateResponse {
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 >= 0 {
41 {
42 crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
43 for it in &self.results {
44 it.encode(buf, version)?;
45 }
46 };
47 }
48 if flex {
49 let tagged = WriteTaggedFields::new();
50 tagged.write(buf, &self.unknown_tagged_fields);
51 }
52 Ok(())
53 }
54 fn encoded_len(&self, version: i16) -> usize {
55 let flex = is_flexible(version);
56 let mut n: usize = 0;
57 if version >= 0 {
58 n += {
59 let prefix =
60 crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
61 let body: usize = (self.results)
62 .iter()
63 .map(|it| it.encoded_len(version))
64 .sum();
65 prefix + body
66 };
67 }
68 if flex {
69 let known_pairs: Vec<(u32, usize)> = Vec::new();
70 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
71 }
72 n
73 }
74}
75impl Decode<'_> for ReadShareGroupStateResponse {
76 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
77 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
78 return Err(ProtocolError::UnsupportedVersion {
79 api_key: API_KEY,
80 version,
81 });
82 }
83 let flex = is_flexible(version);
84 let mut out = Self::default();
85 if version >= 0 {
86 out.results = {
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(ReadStateResult::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 ReadShareGroupStateResponse {
103 #[must_use]
104 pub fn populated(version: i16) -> Self {
105 let mut m = Self::default();
106 if version >= 0 {
107 m.results = vec![ReadStateResult::populated(version)];
108 }
109 m
110 }
111}
112#[derive(Debug, Clone, PartialEq, Eq, Default)]
113pub struct ReadStateResult {
114 pub topic_id: crate::primitives::uuid::Uuid,
115 pub partitions: Vec<PartitionResult>,
116 pub unknown_tagged_fields: UnknownTaggedFields,
117}
118impl Encode for ReadStateResult {
119 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
120 let flex = version >= 0;
121 if version >= 0 {
122 crate::primitives::uuid::put_uuid(buf, self.topic_id);
123 }
124 if version >= 0 {
125 {
126 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
127 for it in &self.partitions {
128 it.encode(buf, version)?;
129 }
130 };
131 }
132 if flex {
133 let tagged = WriteTaggedFields::new();
134 tagged.write(buf, &self.unknown_tagged_fields);
135 }
136 Ok(())
137 }
138 fn encoded_len(&self, version: i16) -> usize {
139 let flex = version >= 0;
140 let mut n: usize = 0;
141 if version >= 0 {
142 n += 16;
143 }
144 if version >= 0 {
145 n += {
146 let prefix =
147 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
148 let body: usize = (self.partitions)
149 .iter()
150 .map(|it| it.encoded_len(version))
151 .sum();
152 prefix + body
153 };
154 }
155 if flex {
156 let known_pairs: Vec<(u32, usize)> = Vec::new();
157 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
158 }
159 n
160 }
161}
162impl Decode<'_> for ReadStateResult {
163 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
164 let flex = version >= 0;
165 let mut out = Self::default();
166 if version >= 0 {
167 out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
168 }
169 if version >= 0 {
170 out.partitions = {
171 let n = crate::primitives::array::get_array_len(buf, flex)?;
172 let mut v = Vec::with_capacity(n);
173 for _ in 0..n {
174 v.push(PartitionResult::decode(buf, version)?);
175 }
176 v
177 };
178 }
179 if flex {
180 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
181 }
182 Ok(out)
183 }
184}
185#[cfg(test)]
186impl ReadStateResult {
187 #[must_use]
188 pub fn populated(version: i16) -> Self {
189 let mut m = Self::default();
190 if version >= 0 {
191 m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
192 }
193 if version >= 0 {
194 m.partitions = vec![PartitionResult::populated(version)];
195 }
196 m
197 }
198}
199#[derive(Debug, Clone, PartialEq, Eq, Default)]
200pub struct PartitionResult {
201 pub partition: i32,
202 pub error_code: i16,
203 pub error_message: Option<String>,
204 pub state_epoch: i32,
205 pub start_offset: i64,
206 pub state_batches: Vec<StateBatch>,
207 pub unknown_tagged_fields: UnknownTaggedFields,
208}
209impl Encode for PartitionResult {
210 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
211 let flex = version >= 0;
212 if version >= 0 {
213 put_i32(buf, self.partition);
214 }
215 if version >= 0 {
216 put_i16(buf, self.error_code);
217 }
218 if version >= 0 {
219 if flex {
220 let () = put_compact_nullable_string(buf, self.error_message.as_deref());
221 } else {
222 let () = put_nullable_string(buf, self.error_message.as_deref());
223 }
224 }
225 if version >= 0 {
226 put_i32(buf, self.state_epoch);
227 }
228 if version >= 0 {
229 put_i64(buf, self.start_offset);
230 }
231 if version >= 0 {
232 {
233 crate::primitives::array::put_array_len(buf, (self.state_batches).len(), flex);
234 for it in &self.state_batches {
235 it.encode(buf, version)?;
236 }
237 };
238 }
239 if flex {
240 let tagged = WriteTaggedFields::new();
241 tagged.write(buf, &self.unknown_tagged_fields);
242 }
243 Ok(())
244 }
245 fn encoded_len(&self, version: i16) -> usize {
246 let flex = version >= 0;
247 let mut n: usize = 0;
248 if version >= 0 {
249 n += 4;
250 }
251 if version >= 0 {
252 n += 2;
253 }
254 if version >= 0 {
255 n += if flex {
256 compact_nullable_string_len(self.error_message.as_deref())
257 } else {
258 nullable_string_len(self.error_message.as_deref())
259 };
260 }
261 if version >= 0 {
262 n += 4;
263 }
264 if version >= 0 {
265 n += 8;
266 }
267 if version >= 0 {
268 n += {
269 let prefix = crate::primitives::array::array_len_prefix_len(
270 (self.state_batches).len(),
271 flex,
272 );
273 let body: usize = (self.state_batches)
274 .iter()
275 .map(|it| it.encoded_len(version))
276 .sum();
277 prefix + body
278 };
279 }
280 if flex {
281 let known_pairs: Vec<(u32, usize)> = Vec::new();
282 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
283 }
284 n
285 }
286}
287impl Decode<'_> for PartitionResult {
288 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
289 let flex = version >= 0;
290 let mut out = Self::default();
291 if version >= 0 {
292 out.partition = get_i32(buf)?;
293 }
294 if version >= 0 {
295 out.error_code = get_i16(buf)?;
296 }
297 if version >= 0 {
298 out.error_message = if flex {
299 get_compact_nullable_string_owned(buf)?
300 } else {
301 get_nullable_string_owned(buf)?
302 };
303 }
304 if version >= 0 {
305 out.state_epoch = get_i32(buf)?;
306 }
307 if version >= 0 {
308 out.start_offset = get_i64(buf)?;
309 }
310 if version >= 0 {
311 out.state_batches = {
312 let n = crate::primitives::array::get_array_len(buf, flex)?;
313 let mut v = Vec::with_capacity(n);
314 for _ in 0..n {
315 v.push(StateBatch::decode(buf, version)?);
316 }
317 v
318 };
319 }
320 if flex {
321 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
322 }
323 Ok(out)
324 }
325}
326#[cfg(test)]
327impl PartitionResult {
328 #[must_use]
329 pub fn populated(version: i16) -> Self {
330 let mut m = Self::default();
331 if version >= 0 {
332 m.partition = 1i32;
333 }
334 if version >= 0 {
335 m.error_code = 1i16;
336 }
337 if version >= 0 {
338 m.error_message = Some("x".to_string());
339 }
340 if version >= 0 {
341 m.state_epoch = 1i32;
342 }
343 if version >= 0 {
344 m.start_offset = 1i64;
345 }
346 if version >= 0 {
347 m.state_batches = vec![StateBatch::populated(version)];
348 }
349 m
350 }
351}
352#[derive(Debug, Clone, PartialEq, Eq, Default)]
353pub struct StateBatch {
354 pub first_offset: i64,
355 pub last_offset: i64,
356 pub delivery_state: i8,
357 pub delivery_count: i16,
358 pub unknown_tagged_fields: UnknownTaggedFields,
359}
360impl Encode for StateBatch {
361 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
362 let flex = version >= 0;
363 if version >= 0 {
364 put_i64(buf, self.first_offset);
365 }
366 if version >= 0 {
367 put_i64(buf, self.last_offset);
368 }
369 if version >= 0 {
370 put_i8(buf, self.delivery_state);
371 }
372 if version >= 0 {
373 put_i16(buf, self.delivery_count);
374 }
375 if flex {
376 let tagged = WriteTaggedFields::new();
377 tagged.write(buf, &self.unknown_tagged_fields);
378 }
379 Ok(())
380 }
381 fn encoded_len(&self, version: i16) -> usize {
382 let flex = version >= 0;
383 let mut n: usize = 0;
384 if version >= 0 {
385 n += 8;
386 }
387 if version >= 0 {
388 n += 8;
389 }
390 if version >= 0 {
391 n += 1;
392 }
393 if version >= 0 {
394 n += 2;
395 }
396 if flex {
397 let known_pairs: Vec<(u32, usize)> = Vec::new();
398 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
399 }
400 n
401 }
402}
403impl Decode<'_> for StateBatch {
404 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
405 let flex = version >= 0;
406 let mut out = Self::default();
407 if version >= 0 {
408 out.first_offset = get_i64(buf)?;
409 }
410 if version >= 0 {
411 out.last_offset = get_i64(buf)?;
412 }
413 if version >= 0 {
414 out.delivery_state = get_i8(buf)?;
415 }
416 if version >= 0 {
417 out.delivery_count = get_i16(buf)?;
418 }
419 if flex {
420 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
421 }
422 Ok(out)
423 }
424}
425#[cfg(test)]
426impl StateBatch {
427 #[must_use]
428 pub fn populated(version: i16) -> Self {
429 let mut m = Self::default();
430 if version >= 0 {
431 m.first_offset = 1i64;
432 }
433 if version >= 0 {
434 m.last_offset = 1i64;
435 }
436 if version >= 0 {
437 m.delivery_state = 1i8;
438 }
439 if version >= 0 {
440 m.delivery_count = 1i16;
441 }
442 m
443 }
444}
445#[must_use]
448#[allow(unused_comparisons)]
449pub fn default_json(_version: i16) -> ::serde_json::Value {
450 let mut obj = ::serde_json::Map::new();
451 obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
452 ::serde_json::Value::Object(obj)
453}