Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
ReadShareGroupStateSummaryResponse.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_i16, get_i32, get_i64, 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 = 87;
20pub const MIN_VERSION: i16 = 0;
21pub const MAX_VERSION: i16 = 1;
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 ReadShareGroupStateSummaryResponse {
30    pub results: Vec<ReadStateSummaryResult>,
31    pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl Encode for ReadShareGroupStateSummaryResponse {
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 ReadShareGroupStateSummaryResponse {
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(ReadStateSummaryResult::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 ReadShareGroupStateSummaryResponse {
104    #[must_use]
105    pub fn populated(version: i16) -> Self {
106        let mut m = Self::default();
107        if version >= 0 {
108            m.results = vec![ReadStateSummaryResult::populated(version)];
109        }
110        m
111    }
112}
113#[derive(Debug, Clone, PartialEq, Eq, Default)]
114pub struct ReadStateSummaryResult {
115    pub topic_id: Uuid,
116    pub partitions: Vec<PartitionResult>,
117    pub unknown_tagged_fields: UnknownTaggedFields,
118}
119impl Encode for ReadStateSummaryResult {
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 ReadStateSummaryResult {
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 ReadStateSummaryResult {
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)]
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 leader_epoch: i32,
206    pub start_offset: i64,
207    pub delivery_complete_count: i32,
208    pub unknown_tagged_fields: UnknownTaggedFields,
209}
210impl Default for PartitionResult {
211    fn default() -> Self {
212        Self {
213            partition: 0i32,
214            error_code: 0i16,
215            error_message: None,
216            state_epoch: 0i32,
217            leader_epoch: 0i32,
218            start_offset: 0i64,
219            delivery_complete_count: -1i32,
220            unknown_tagged_fields: UnknownTaggedFields::default(),
221        }
222    }
223}
224impl Encode for PartitionResult {
225    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
226        let flex = version >= 0;
227        if version >= 0 {
228            put_i32(buf, self.partition);
229        }
230        if version >= 0 {
231            put_i16(buf, self.error_code);
232        }
233        if version >= 0 {
234            if flex {
235                put_compact_nullable_string(buf, self.error_message.as_deref())?;
236            } else {
237                put_nullable_string(buf, self.error_message.as_deref())?;
238            }
239        }
240        if version >= 0 {
241            put_i32(buf, self.state_epoch);
242        }
243        if version >= 0 {
244            put_i32(buf, self.leader_epoch);
245        }
246        if version >= 0 {
247            put_i64(buf, self.start_offset);
248        }
249        if version >= 1 {
250            put_i32(buf, self.delivery_complete_count);
251        }
252        if flex {
253            let tagged = WriteTaggedFields::new();
254            tagged.write(buf, &self.unknown_tagged_fields)?;
255        }
256        Ok(())
257    }
258    fn encoded_len(&self, version: i16) -> usize {
259        let flex = version >= 0;
260        let mut n: usize = 0;
261        if version >= 0 {
262            n += 4;
263        }
264        if version >= 0 {
265            n += 2;
266        }
267        if version >= 0 {
268            n += if flex {
269                compact_nullable_string_len(self.error_message.as_deref())
270            } else {
271                nullable_string_len(self.error_message.as_deref())
272            };
273        }
274        if version >= 0 {
275            n += 4;
276        }
277        if version >= 0 {
278            n += 4;
279        }
280        if version >= 0 {
281            n += 8;
282        }
283        if version >= 1 {
284            n += 4;
285        }
286        if flex {
287            let known_pairs: Vec<(u32, usize)> = Vec::new();
288            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
289        }
290        n
291    }
292}
293impl Decode<'_> for PartitionResult {
294    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
295        let flex = version >= 0;
296        let mut out = Self::default();
297        if version >= 0 {
298            out.partition = get_i32(buf)?;
299        }
300        if version >= 0 {
301            out.error_code = get_i16(buf)?;
302        }
303        if version >= 0 {
304            out.error_message = if flex {
305                get_compact_nullable_string_owned(buf)?
306            } else {
307                get_nullable_string_owned(buf)?
308            };
309        }
310        if version >= 0 {
311            out.state_epoch = get_i32(buf)?;
312        }
313        if version >= 0 {
314            out.leader_epoch = get_i32(buf)?;
315        }
316        if version >= 0 {
317            out.start_offset = get_i64(buf)?;
318        }
319        if version >= 1 {
320            out.delivery_complete_count = get_i32(buf)?;
321        }
322        if flex {
323            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
324        }
325        Ok(out)
326    }
327}
328#[cfg(test)]
329impl PartitionResult {
330    #[must_use]
331    pub fn populated(version: i16) -> Self {
332        let mut m = Self::default();
333        if version >= 0 {
334            m.partition = 1i32;
335        }
336        if version >= 0 {
337            m.error_code = 1i16;
338        }
339        if version >= 0 {
340            m.error_message = Some("x".to_owned());
341        }
342        if version >= 0 {
343            m.state_epoch = 1i32;
344        }
345        if version >= 0 {
346            m.leader_epoch = 1i32;
347        }
348        if version >= 0 {
349            m.start_offset = 1i64;
350        }
351        if version >= 1 {
352            m.delivery_complete_count = 1i32;
353        }
354        m
355    }
356}
357/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
358/// Only includes fields valid for the given version.
359#[must_use]
360#[allow(unused_comparisons)]
361pub fn default_json(_version: i16) -> ::serde_json::Value {
362    let mut obj = ::serde_json::Map::new();
363    obj.insert("results".to_owned(), ::serde_json::Value::Array(vec![]));
364    ::serde_json::Value::Object(obj)
365}