Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
4use crate::primitives::string_bytes::{
5    compact_nullable_string_len, get_compact_nullable_string_owned, get_nullable_string_owned,
6    nullable_string_len, put_compact_nullable_string, put_nullable_string,
7};
8use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
9use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
10use bytes::{Buf, BufMut};
11pub const API_KEY: i16 = 83;
12pub const MIN_VERSION: i16 = 0;
13pub const MAX_VERSION: i16 = 0;
14pub const FLEXIBLE_MIN: i16 = 0;
15#[inline]
16fn is_flexible(version: i16) -> bool {
17    version >= FLEXIBLE_MIN
18}
19#[derive(Debug, Clone, PartialEq, Eq, Default)]
20pub struct InitializeShareGroupStateResponse {
21    pub results: Vec<InitializeStateResult>,
22    pub unknown_tagged_fields: UnknownTaggedFields,
23}
24impl Encode for InitializeShareGroupStateResponse {
25    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
26        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
27            return Err(ProtocolError::UnsupportedVersion {
28                api_key: API_KEY,
29                version,
30            });
31        }
32        let flex = is_flexible(version);
33        if version >= 0 {
34            {
35                crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
36                for it in &self.results {
37                    it.encode(buf, version)?;
38                }
39            }
40        }
41        if flex {
42            let tagged = WriteTaggedFields::new();
43            tagged.write(buf, &self.unknown_tagged_fields);
44        }
45        Ok(())
46    }
47    fn encoded_len(&self, version: i16) -> usize {
48        let flex = is_flexible(version);
49        let mut n: usize = 0;
50        if version >= 0 {
51            n += {
52                let prefix =
53                    crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
54                let body: usize = (self.results)
55                    .iter()
56                    .map(|it| it.encoded_len(version))
57                    .sum();
58                prefix + body
59            };
60        }
61        if flex {
62            let known_pairs: Vec<(u32, usize)> = Vec::new();
63            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
64        }
65        n
66    }
67}
68impl Decode<'_> for InitializeShareGroupStateResponse {
69    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
70        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
71            return Err(ProtocolError::UnsupportedVersion {
72                api_key: API_KEY,
73                version,
74            });
75        }
76        let flex = is_flexible(version);
77        let mut out = Self::default();
78        if version >= 0 {
79            out.results = {
80                let n = crate::primitives::array::get_array_len(buf, flex)?;
81                let mut v = Vec::with_capacity(n);
82                for _ in 0..n {
83                    v.push(InitializeStateResult::decode(buf, version)?);
84                }
85                v
86            };
87        }
88        if flex {
89            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
90        }
91        Ok(out)
92    }
93}
94#[cfg(test)]
95impl InitializeShareGroupStateResponse {
96    #[must_use]
97    pub fn populated(version: i16) -> Self {
98        let mut m = Self::default();
99        if version >= 0 {
100            m.results = vec![InitializeStateResult::populated(version)];
101        }
102        m
103    }
104}
105#[derive(Debug, Clone, PartialEq, Eq, Default)]
106pub struct InitializeStateResult {
107    pub topic_id: crate::primitives::uuid::Uuid,
108    pub partitions: Vec<PartitionResult>,
109    pub unknown_tagged_fields: UnknownTaggedFields,
110}
111impl Encode for InitializeStateResult {
112    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
113        let flex = version >= 0;
114        if version >= 0 {
115            crate::primitives::uuid::put_uuid(buf, self.topic_id);
116        }
117        if version >= 0 {
118            {
119                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
120                for it in &self.partitions {
121                    it.encode(buf, version)?;
122                }
123            }
124        }
125        if flex {
126            let tagged = WriteTaggedFields::new();
127            tagged.write(buf, &self.unknown_tagged_fields);
128        }
129        Ok(())
130    }
131    fn encoded_len(&self, version: i16) -> usize {
132        let flex = version >= 0;
133        let mut n: usize = 0;
134        if version >= 0 {
135            n += 16;
136        }
137        if version >= 0 {
138            n += {
139                let prefix =
140                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
141                let body: usize = (self.partitions)
142                    .iter()
143                    .map(|it| it.encoded_len(version))
144                    .sum();
145                prefix + body
146            };
147        }
148        if flex {
149            let known_pairs: Vec<(u32, usize)> = Vec::new();
150            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
151        }
152        n
153    }
154}
155impl Decode<'_> for InitializeStateResult {
156    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
157        let flex = version >= 0;
158        let mut out = Self::default();
159        if version >= 0 {
160            out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
161        }
162        if version >= 0 {
163            out.partitions = {
164                let n = crate::primitives::array::get_array_len(buf, flex)?;
165                let mut v = Vec::with_capacity(n);
166                for _ in 0..n {
167                    v.push(PartitionResult::decode(buf, version)?);
168                }
169                v
170            };
171        }
172        if flex {
173            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
174        }
175        Ok(out)
176    }
177}
178#[cfg(test)]
179impl InitializeStateResult {
180    #[must_use]
181    pub fn populated(version: i16) -> Self {
182        let mut m = Self::default();
183        if version >= 0 {
184            m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
185        }
186        if version >= 0 {
187            m.partitions = vec![PartitionResult::populated(version)];
188        }
189        m
190    }
191}
192#[derive(Debug, Clone, PartialEq, Eq, Default)]
193pub struct PartitionResult {
194    pub partition: i32,
195    pub error_code: i16,
196    pub error_message: Option<String>,
197    pub unknown_tagged_fields: UnknownTaggedFields,
198}
199impl Encode for PartitionResult {
200    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
201        let flex = version >= 0;
202        if version >= 0 {
203            put_i32(buf, self.partition);
204        }
205        if version >= 0 {
206            put_i16(buf, self.error_code);
207        }
208        if version >= 0 {
209            if flex {
210                put_compact_nullable_string(buf, self.error_message.as_deref());
211            } else {
212                put_nullable_string(buf, self.error_message.as_deref());
213            }
214        }
215        if flex {
216            let tagged = WriteTaggedFields::new();
217            tagged.write(buf, &self.unknown_tagged_fields);
218        }
219        Ok(())
220    }
221    fn encoded_len(&self, version: i16) -> usize {
222        let flex = version >= 0;
223        let mut n: usize = 0;
224        if version >= 0 {
225            n += 4;
226        }
227        if version >= 0 {
228            n += 2;
229        }
230        if version >= 0 {
231            n += if flex {
232                compact_nullable_string_len(self.error_message.as_deref())
233            } else {
234                nullable_string_len(self.error_message.as_deref())
235            };
236        }
237        if flex {
238            let known_pairs: Vec<(u32, usize)> = Vec::new();
239            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
240        }
241        n
242    }
243}
244impl Decode<'_> for PartitionResult {
245    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
246        let flex = version >= 0;
247        let mut out = Self::default();
248        if version >= 0 {
249            out.partition = get_i32(buf)?;
250        }
251        if version >= 0 {
252            out.error_code = get_i16(buf)?;
253        }
254        if version >= 0 {
255            out.error_message = if flex {
256                get_compact_nullable_string_owned(buf)?
257            } else {
258                get_nullable_string_owned(buf)?
259            };
260        }
261        if flex {
262            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
263        }
264        Ok(out)
265    }
266}
267#[cfg(test)]
268impl PartitionResult {
269    #[must_use]
270    pub fn populated(version: i16) -> Self {
271        let mut m = Self::default();
272        if version >= 0 {
273            m.partition = 1i32;
274        }
275        if version >= 0 {
276            m.error_code = 1i16;
277        }
278        if version >= 0 {
279            m.error_message = Some("x".to_string());
280        }
281        m
282    }
283}
284/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
285/// Only includes fields valid for the given version.
286#[must_use]
287#[allow(unused_comparisons)]
288pub fn default_json(version: i16) -> ::serde_json::Value {
289    let mut obj = ::serde_json::Map::new();
290    obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
291    ::serde_json::Value::Object(obj)
292}