Skip to main content

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

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