Skip to main content

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

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