Skip to main content

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