Skip to main content

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

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