Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
ReadShareGroupStateResponse.owned.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::{
6    Decode, Encode, ProtocolError, UnknownTaggedFields,
7    primitives::{
8        array::{array_len_prefix_len, get_array_len, put_array_len},
9        fixed::{get_i8, get_i16, get_i32, get_i64, put_i8, put_i16, put_i32, put_i64},
10        string_bytes::{
11            compact_nullable_string_len, get_compact_nullable_string_owned,
12            get_nullable_string_owned, nullable_string_len, put_compact_nullable_string,
13            put_nullable_string,
14        },
15        uuid::{Uuid, get_uuid, put_uuid},
16    },
17    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
18};
19pub const API_KEY: i16 = 84;
20pub const MIN_VERSION: i16 = 0;
21pub const MAX_VERSION: i16 = 0;
22pub const FLEXIBLE_MIN: i16 = 0;
23#[inline]
24#[must_use]
25pub fn is_flexible(version: i16) -> bool {
26    version >= FLEXIBLE_MIN
27}
28#[derive(Debug, Clone, PartialEq, Eq, Default)]
29pub struct ReadShareGroupStateResponse {
30    pub results: Vec<ReadStateResult>,
31    pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl Encode for ReadShareGroupStateResponse {
34    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
35        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
36            return Err(ProtocolError::UnsupportedVersion {
37                api_key: API_KEY,
38                version,
39            });
40        }
41        let flex = is_flexible(version);
42        if version >= 0 {
43            {
44                put_array_len(buf, (self.results).len(), flex)?;
45                for it in &self.results {
46                    it.encode(buf, version)?;
47                }
48            }
49        }
50        if flex {
51            let tagged = WriteTaggedFields::new();
52            tagged.write(buf, &self.unknown_tagged_fields)?;
53        }
54        Ok(())
55    }
56    fn encoded_len(&self, version: i16) -> usize {
57        let flex = is_flexible(version);
58        let mut n: usize = 0;
59        if version >= 0 {
60            n += {
61                let prefix = array_len_prefix_len((self.results).len(), flex);
62                let body: usize = (self.results)
63                    .iter()
64                    .map(|it| it.encoded_len(version))
65                    .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 ReadShareGroupStateResponse {
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 >= 0 {
87            out.results = {
88                let n = get_array_len(buf, flex)?;
89                let mut v = Vec::with_capacity(n);
90                for _ in 0..n {
91                    v.push(ReadStateResult::decode(buf, version)?);
92                }
93                v
94            };
95        }
96        if flex {
97            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
98        }
99        Ok(out)
100    }
101}
102#[cfg(test)]
103impl ReadShareGroupStateResponse {
104    #[must_use]
105    pub fn populated(version: i16) -> Self {
106        let mut m = Self::default();
107        if version >= 0 {
108            m.results = vec![ReadStateResult::populated(version)];
109        }
110        m
111    }
112}
113#[derive(Debug, Clone, PartialEq, Eq, Default)]
114pub struct ReadStateResult {
115    pub topic_id: Uuid,
116    pub partitions: Vec<PartitionResult>,
117    pub unknown_tagged_fields: UnknownTaggedFields,
118}
119impl Encode for ReadStateResult {
120    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
121        let flex = version >= 0;
122        if version >= 0 {
123            put_uuid(buf, self.topic_id);
124        }
125        if version >= 0 {
126            {
127                put_array_len(buf, (self.partitions).len(), flex)?;
128                for it in &self.partitions {
129                    it.encode(buf, version)?;
130                }
131            }
132        }
133        if flex {
134            let tagged = WriteTaggedFields::new();
135            tagged.write(buf, &self.unknown_tagged_fields)?;
136        }
137        Ok(())
138    }
139    fn encoded_len(&self, version: i16) -> usize {
140        let flex = version >= 0;
141        let mut n: usize = 0;
142        if version >= 0 {
143            n += 16;
144        }
145        if version >= 0 {
146            n += {
147                let prefix = 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 = get_uuid(buf)?;
168        }
169        if version >= 0 {
170            out.partitions = {
171                let n = 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 = 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                put_compact_nullable_string(buf, self.error_message.as_deref())?;
221            } else {
222                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                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 = array_len_prefix_len((self.state_batches).len(), flex);
270                let body: usize = (self.state_batches)
271                    .iter()
272                    .map(|it| it.encoded_len(version))
273                    .sum();
274                prefix + body
275            };
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 PartitionResult {
285    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
286        let flex = version >= 0;
287        let mut out = Self::default();
288        if version >= 0 {
289            out.partition = get_i32(buf)?;
290        }
291        if version >= 0 {
292            out.error_code = get_i16(buf)?;
293        }
294        if version >= 0 {
295            out.error_message = if flex {
296                get_compact_nullable_string_owned(buf)?
297            } else {
298                get_nullable_string_owned(buf)?
299            };
300        }
301        if version >= 0 {
302            out.state_epoch = get_i32(buf)?;
303        }
304        if version >= 0 {
305            out.start_offset = get_i64(buf)?;
306        }
307        if version >= 0 {
308            out.state_batches = {
309                let n = get_array_len(buf, flex)?;
310                let mut v = Vec::with_capacity(n);
311                for _ in 0..n {
312                    v.push(StateBatch::decode(buf, version)?);
313                }
314                v
315            };
316        }
317        if flex {
318            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
319        }
320        Ok(out)
321    }
322}
323#[cfg(test)]
324impl PartitionResult {
325    #[must_use]
326    pub fn populated(version: i16) -> Self {
327        let mut m = Self::default();
328        if version >= 0 {
329            m.partition = 1i32;
330        }
331        if version >= 0 {
332            m.error_code = 1i16;
333        }
334        if version >= 0 {
335            m.error_message = Some("x".to_owned());
336        }
337        if version >= 0 {
338            m.state_epoch = 1i32;
339        }
340        if version >= 0 {
341            m.start_offset = 1i64;
342        }
343        if version >= 0 {
344            m.state_batches = vec![StateBatch::populated(version)];
345        }
346        m
347    }
348}
349#[derive(Debug, Clone, PartialEq, Eq, Default)]
350pub struct StateBatch {
351    pub first_offset: i64,
352    pub last_offset: i64,
353    pub delivery_state: i8,
354    pub delivery_count: i16,
355    pub unknown_tagged_fields: UnknownTaggedFields,
356}
357impl Encode for StateBatch {
358    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
359        let flex = version >= 0;
360        if version >= 0 {
361            put_i64(buf, self.first_offset);
362        }
363        if version >= 0 {
364            put_i64(buf, self.last_offset);
365        }
366        if version >= 0 {
367            put_i8(buf, self.delivery_state);
368        }
369        if version >= 0 {
370            put_i16(buf, self.delivery_count);
371        }
372        if flex {
373            let tagged = WriteTaggedFields::new();
374            tagged.write(buf, &self.unknown_tagged_fields)?;
375        }
376        Ok(())
377    }
378    fn encoded_len(&self, version: i16) -> usize {
379        let flex = version >= 0;
380        let mut n: usize = 0;
381        if version >= 0 {
382            n += 8;
383        }
384        if version >= 0 {
385            n += 8;
386        }
387        if version >= 0 {
388            n += 1;
389        }
390        if version >= 0 {
391            n += 2;
392        }
393        if flex {
394            let known_pairs: Vec<(u32, usize)> = Vec::new();
395            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
396        }
397        n
398    }
399}
400impl Decode<'_> for StateBatch {
401    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
402        let flex = version >= 0;
403        let mut out = Self::default();
404        if version >= 0 {
405            out.first_offset = get_i64(buf)?;
406        }
407        if version >= 0 {
408            out.last_offset = get_i64(buf)?;
409        }
410        if version >= 0 {
411            out.delivery_state = get_i8(buf)?;
412        }
413        if version >= 0 {
414            out.delivery_count = get_i16(buf)?;
415        }
416        if flex {
417            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
418        }
419        Ok(out)
420    }
421}
422#[cfg(test)]
423impl StateBatch {
424    #[must_use]
425    pub fn populated(version: i16) -> Self {
426        let mut m = Self::default();
427        if version >= 0 {
428            m.first_offset = 1i64;
429        }
430        if version >= 0 {
431            m.last_offset = 1i64;
432        }
433        if version >= 0 {
434            m.delivery_state = 1i8;
435        }
436        if version >= 0 {
437            m.delivery_count = 1i16;
438        }
439        m
440    }
441}
442/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
443/// Only includes fields valid for the given version.
444#[must_use]
445#[allow(unused_comparisons)]
446pub fn default_json(_version: i16) -> ::serde_json::Value {
447    let mut obj = ::serde_json::Map::new();
448    obj.insert("results".to_owned(), ::serde_json::Value::Array(vec![]));
449    ::serde_json::Value::Object(obj)
450}