Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
InitializeShareGroupStateResponse.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, put_i16, put_i32},
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 = 83;
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 InitializeShareGroupStateResponse {
30    pub results: Vec<InitializeStateResult>,
31    pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl Encode for InitializeShareGroupStateResponse {
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 InitializeShareGroupStateResponse {
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(InitializeStateResult::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 InitializeShareGroupStateResponse {
104    #[must_use]
105    pub fn populated(version: i16) -> Self {
106        let mut m = Self::default();
107        if version >= 0 {
108            m.results = vec![InitializeStateResult::populated(version)];
109        }
110        m
111    }
112}
113#[derive(Debug, Clone, PartialEq, Eq, Default)]
114pub struct InitializeStateResult {
115    pub topic_id: Uuid,
116    pub partitions: Vec<PartitionResult>,
117    pub unknown_tagged_fields: UnknownTaggedFields,
118}
119impl Encode for InitializeStateResult {
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 InitializeStateResult {
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 InitializeStateResult {
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 unknown_tagged_fields: UnknownTaggedFields,
205}
206impl Encode for PartitionResult {
207    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
208        let flex = version >= 0;
209        if version >= 0 {
210            put_i32(buf, self.partition);
211        }
212        if version >= 0 {
213            put_i16(buf, self.error_code);
214        }
215        if version >= 0 {
216            if flex {
217                put_compact_nullable_string(buf, self.error_message.as_deref())?;
218            } else {
219                put_nullable_string(buf, self.error_message.as_deref())?;
220            }
221        }
222        if flex {
223            let tagged = WriteTaggedFields::new();
224            tagged.write(buf, &self.unknown_tagged_fields)?;
225        }
226        Ok(())
227    }
228    fn encoded_len(&self, version: i16) -> usize {
229        let flex = version >= 0;
230        let mut n: usize = 0;
231        if version >= 0 {
232            n += 4;
233        }
234        if version >= 0 {
235            n += 2;
236        }
237        if version >= 0 {
238            n += if flex {
239                compact_nullable_string_len(self.error_message.as_deref())
240            } else {
241                nullable_string_len(self.error_message.as_deref())
242            };
243        }
244        if flex {
245            let known_pairs: Vec<(u32, usize)> = Vec::new();
246            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
247        }
248        n
249    }
250}
251impl Decode<'_> for PartitionResult {
252    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
253        let flex = version >= 0;
254        let mut out = Self::default();
255        if version >= 0 {
256            out.partition = get_i32(buf)?;
257        }
258        if version >= 0 {
259            out.error_code = get_i16(buf)?;
260        }
261        if version >= 0 {
262            out.error_message = if flex {
263                get_compact_nullable_string_owned(buf)?
264            } else {
265                get_nullable_string_owned(buf)?
266            };
267        }
268        if flex {
269            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
270        }
271        Ok(out)
272    }
273}
274#[cfg(test)]
275impl PartitionResult {
276    #[must_use]
277    pub fn populated(version: i16) -> Self {
278        let mut m = Self::default();
279        if version >= 0 {
280            m.partition = 1i32;
281        }
282        if version >= 0 {
283            m.error_code = 1i16;
284        }
285        if version >= 0 {
286            m.error_message = Some("x".to_owned());
287        }
288        m
289    }
290}
291/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
292/// Only includes fields valid for the given version.
293#[must_use]
294#[allow(unused_comparisons)]
295pub fn default_json(_version: i16) -> ::serde_json::Value {
296    let mut obj = ::serde_json::Map::new();
297    obj.insert("results".to_owned(), ::serde_json::Value::Array(vec![]));
298    ::serde_json::Value::Object(obj)
299}