Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AlterShareGroupOffsetsResponse.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, compact_string_len, get_compact_nullable_string_owned,
6    get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
7    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
8};
9use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
10use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
11use bytes::{Buf, BufMut};
12pub const API_KEY: i16 = 91;
13pub const MIN_VERSION: i16 = 0;
14pub const MAX_VERSION: i16 = 0;
15pub const FLEXIBLE_MIN: i16 = 0;
16#[inline]
17fn is_flexible(version: i16) -> bool {
18    version >= FLEXIBLE_MIN
19}
20#[derive(Debug, Clone, PartialEq, Eq, Default)]
21pub struct AlterShareGroupOffsetsResponse {
22    pub throttle_time_ms: i32,
23    pub error_code: i16,
24    pub error_message: Option<String>,
25    pub responses: Vec<AlterShareGroupOffsetsResponseTopic>,
26    pub unknown_tagged_fields: UnknownTaggedFields,
27}
28impl Encode for AlterShareGroupOffsetsResponse {
29    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
30        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
31            return Err(ProtocolError::UnsupportedVersion {
32                api_key: API_KEY,
33                version,
34            });
35        }
36        let flex = is_flexible(version);
37        if version >= 0 {
38            put_i32(buf, self.throttle_time_ms);
39        }
40        if version >= 0 {
41            put_i16(buf, self.error_code);
42        }
43        if version >= 0 {
44            if flex {
45                put_compact_nullable_string(buf, self.error_message.as_deref());
46            } else {
47                put_nullable_string(buf, self.error_message.as_deref());
48            }
49        }
50        if version >= 0 {
51            {
52                crate::primitives::array::put_array_len(buf, (self.responses).len(), flex);
53                for it in &self.responses {
54                    it.encode(buf, version)?;
55                }
56            }
57        }
58        if flex {
59            let tagged = WriteTaggedFields::new();
60            tagged.write(buf, &self.unknown_tagged_fields);
61        }
62        Ok(())
63    }
64    fn encoded_len(&self, version: i16) -> usize {
65        let flex = is_flexible(version);
66        let mut n: usize = 0;
67        if version >= 0 {
68            n += 4;
69        }
70        if version >= 0 {
71            n += 2;
72        }
73        if version >= 0 {
74            n += if flex {
75                compact_nullable_string_len(self.error_message.as_deref())
76            } else {
77                nullable_string_len(self.error_message.as_deref())
78            };
79        }
80        if version >= 0 {
81            n += {
82                let prefix =
83                    crate::primitives::array::array_len_prefix_len((self.responses).len(), flex);
84                let body: usize = (self.responses)
85                    .iter()
86                    .map(|it| it.encoded_len(version))
87                    .sum();
88                prefix + body
89            };
90        }
91        if flex {
92            let known_pairs: Vec<(u32, usize)> = Vec::new();
93            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
94        }
95        n
96    }
97}
98impl Decode<'_> for AlterShareGroupOffsetsResponse {
99    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
100        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
101            return Err(ProtocolError::UnsupportedVersion {
102                api_key: API_KEY,
103                version,
104            });
105        }
106        let flex = is_flexible(version);
107        let mut out = Self::default();
108        if version >= 0 {
109            out.throttle_time_ms = get_i32(buf)?;
110        }
111        if version >= 0 {
112            out.error_code = get_i16(buf)?;
113        }
114        if version >= 0 {
115            out.error_message = if flex {
116                get_compact_nullable_string_owned(buf)?
117            } else {
118                get_nullable_string_owned(buf)?
119            };
120        }
121        if version >= 0 {
122            out.responses = {
123                let n = crate::primitives::array::get_array_len(buf, flex)?;
124                let mut v = Vec::with_capacity(n);
125                for _ in 0..n {
126                    v.push(AlterShareGroupOffsetsResponseTopic::decode(buf, version)?);
127                }
128                v
129            };
130        }
131        if flex {
132            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
133        }
134        Ok(out)
135    }
136}
137#[cfg(test)]
138impl AlterShareGroupOffsetsResponse {
139    #[must_use]
140    pub fn populated(version: i16) -> Self {
141        let mut m = Self::default();
142        if version >= 0 {
143            m.throttle_time_ms = 1i32;
144        }
145        if version >= 0 {
146            m.error_code = 1i16;
147        }
148        if version >= 0 {
149            m.error_message = Some("x".to_string());
150        }
151        if version >= 0 {
152            m.responses = vec![AlterShareGroupOffsetsResponseTopic::populated(version)];
153        }
154        m
155    }
156}
157#[derive(Debug, Clone, PartialEq, Eq, Default)]
158pub struct AlterShareGroupOffsetsResponseTopic {
159    pub topic_name: String,
160    pub topic_id: crate::primitives::uuid::Uuid,
161    pub partitions: Vec<AlterShareGroupOffsetsResponsePartition>,
162    pub unknown_tagged_fields: UnknownTaggedFields,
163}
164impl Encode for AlterShareGroupOffsetsResponseTopic {
165    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
166        let flex = version >= 0;
167        if version >= 0 {
168            if flex {
169                put_compact_string(buf, &self.topic_name);
170            } else {
171                put_string(buf, &self.topic_name);
172            }
173        }
174        if version >= 0 {
175            crate::primitives::uuid::put_uuid(buf, self.topic_id);
176        }
177        if version >= 0 {
178            {
179                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
180                for it in &self.partitions {
181                    it.encode(buf, version)?;
182                }
183            }
184        }
185        if flex {
186            let tagged = WriteTaggedFields::new();
187            tagged.write(buf, &self.unknown_tagged_fields);
188        }
189        Ok(())
190    }
191    fn encoded_len(&self, version: i16) -> usize {
192        let flex = version >= 0;
193        let mut n: usize = 0;
194        if version >= 0 {
195            n += if flex {
196                compact_string_len(&self.topic_name)
197            } else {
198                string_len(&self.topic_name)
199            };
200        }
201        if version >= 0 {
202            n += 16;
203        }
204        if version >= 0 {
205            n += {
206                let prefix =
207                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
208                let body: usize = (self.partitions)
209                    .iter()
210                    .map(|it| it.encoded_len(version))
211                    .sum();
212                prefix + body
213            };
214        }
215        if flex {
216            let known_pairs: Vec<(u32, usize)> = Vec::new();
217            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
218        }
219        n
220    }
221}
222impl Decode<'_> for AlterShareGroupOffsetsResponseTopic {
223    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
224        let flex = version >= 0;
225        let mut out = Self::default();
226        if version >= 0 {
227            out.topic_name = if flex {
228                get_compact_string_owned(buf)?
229            } else {
230                get_string_owned(buf)?
231            };
232        }
233        if version >= 0 {
234            out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
235        }
236        if version >= 0 {
237            out.partitions = {
238                let n = crate::primitives::array::get_array_len(buf, flex)?;
239                let mut v = Vec::with_capacity(n);
240                for _ in 0..n {
241                    v.push(AlterShareGroupOffsetsResponsePartition::decode(
242                        buf, version,
243                    )?);
244                }
245                v
246            };
247        }
248        if flex {
249            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
250        }
251        Ok(out)
252    }
253}
254#[cfg(test)]
255impl AlterShareGroupOffsetsResponseTopic {
256    #[must_use]
257    pub fn populated(version: i16) -> Self {
258        let mut m = Self::default();
259        if version >= 0 {
260            m.topic_name = "x".to_string();
261        }
262        if version >= 0 {
263            m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
264        }
265        if version >= 0 {
266            m.partitions = vec![AlterShareGroupOffsetsResponsePartition::populated(version)];
267        }
268        m
269    }
270}
271#[derive(Debug, Clone, PartialEq, Eq, Default)]
272pub struct AlterShareGroupOffsetsResponsePartition {
273    pub partition_index: i32,
274    pub error_code: i16,
275    pub error_message: Option<String>,
276    pub unknown_tagged_fields: UnknownTaggedFields,
277}
278impl Encode for AlterShareGroupOffsetsResponsePartition {
279    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
280        let flex = version >= 0;
281        if version >= 0 {
282            put_i32(buf, self.partition_index);
283        }
284        if version >= 0 {
285            put_i16(buf, self.error_code);
286        }
287        if version >= 0 {
288            if flex {
289                put_compact_nullable_string(buf, self.error_message.as_deref());
290            } else {
291                put_nullable_string(buf, self.error_message.as_deref());
292            }
293        }
294        if flex {
295            let tagged = WriteTaggedFields::new();
296            tagged.write(buf, &self.unknown_tagged_fields);
297        }
298        Ok(())
299    }
300    fn encoded_len(&self, version: i16) -> usize {
301        let flex = version >= 0;
302        let mut n: usize = 0;
303        if version >= 0 {
304            n += 4;
305        }
306        if version >= 0 {
307            n += 2;
308        }
309        if version >= 0 {
310            n += if flex {
311                compact_nullable_string_len(self.error_message.as_deref())
312            } else {
313                nullable_string_len(self.error_message.as_deref())
314            };
315        }
316        if flex {
317            let known_pairs: Vec<(u32, usize)> = Vec::new();
318            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
319        }
320        n
321    }
322}
323impl Decode<'_> for AlterShareGroupOffsetsResponsePartition {
324    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
325        let flex = version >= 0;
326        let mut out = Self::default();
327        if version >= 0 {
328            out.partition_index = get_i32(buf)?;
329        }
330        if version >= 0 {
331            out.error_code = get_i16(buf)?;
332        }
333        if version >= 0 {
334            out.error_message = if flex {
335                get_compact_nullable_string_owned(buf)?
336            } else {
337                get_nullable_string_owned(buf)?
338            };
339        }
340        if flex {
341            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
342        }
343        Ok(out)
344    }
345}
346#[cfg(test)]
347impl AlterShareGroupOffsetsResponsePartition {
348    #[must_use]
349    pub fn populated(version: i16) -> Self {
350        let mut m = Self::default();
351        if version >= 0 {
352            m.partition_index = 1i32;
353        }
354        if version >= 0 {
355            m.error_code = 1i16;
356        }
357        if version >= 0 {
358            m.error_message = Some("x".to_string());
359        }
360        m
361    }
362}
363/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
364/// Only includes fields valid for the given version.
365#[must_use]
366#[allow(unused_comparisons)]
367pub fn default_json(version: i16) -> ::serde_json::Value {
368    let mut obj = ::serde_json::Map::new();
369    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
370    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
371    obj.insert("errorMessage".to_string(), ::serde_json::Value::Null);
372    obj.insert("responses".to_string(), ::serde_json::Value::Array(vec![]));
373    ::serde_json::Value::Object(obj)
374}