Skip to main content

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

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