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 bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i32, put_i32};
6use crate::primitives::string_bytes::{
7    compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8    get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
10    string_len,
11};
12use crate::primitives::string_bytes::{bytes_len, compact_bytes_len, get_bytes_owned, get_compact_bytes_owned, put_bytes, put_compact_bytes};
13use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
14use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
15
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
21#[inline]
22fn is_flexible(version: i16) -> bool { 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}
36
37impl Default for JoinGroupRequest {
38    fn default() -> Self {
39        Self {
40            group_id: String::new(),
41            session_timeout_ms: 0i32,
42            rebalance_timeout_ms: -1i32,
43            member_id: String::new(),
44            group_instance_id: None,
45            protocol_type: String::new(),
46            protocols: Vec::new(),
47            reason: None,
48            unknown_tagged_fields: Default::default(),
49        }
50    }
51}
52
53impl Encode for JoinGroupRequest {
54    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
55        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
56            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
57        }
58        let flex = is_flexible(version);
59        if version >= 0 { if flex { put_compact_string(buf, &self.group_id) } else { put_string(buf, &self.group_id) } }
60        if version >= 0 { put_i32(buf, self.session_timeout_ms) }
61        if version >= 1 { put_i32(buf, self.rebalance_timeout_ms) }
62        if version >= 0 { if flex { put_compact_string(buf, &self.member_id) } else { put_string(buf, &self.member_id) } }
63        if version >= 5 { if flex { put_compact_nullable_string(buf, self.group_instance_id.as_deref()) } else { put_nullable_string(buf, self.group_instance_id.as_deref()) } }
64        if version >= 0 { if flex { put_compact_string(buf, &self.protocol_type) } else { put_string(buf, &self.protocol_type) } }
65        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.protocols).len(), flex); for it in &self.protocols { it.encode(buf, version)?; } } }
66        if version >= 8 { if flex { put_compact_nullable_string(buf, self.reason.as_deref()) } else { put_nullable_string(buf, self.reason.as_deref()) } }
67        if flex {
68            let tagged = WriteTaggedFields::new();
69            tagged.write(buf, &self.unknown_tagged_fields);
70        }
71        Ok(())
72    }
73    fn encoded_len(&self, version: i16) -> usize {
74        let flex = is_flexible(version);
75        let mut n: usize = 0;
76        if version >= 0 { n += if flex { compact_string_len(&self.group_id) } else { string_len(&self.group_id) }; }
77        if version >= 0 { n += 4; }
78        if version >= 1 { n += 4; }
79        if version >= 0 { n += if flex { compact_string_len(&self.member_id) } else { string_len(&self.member_id) }; }
80        if version >= 5 { n += if flex { compact_nullable_string_len(self.group_instance_id.as_deref()) } else { nullable_string_len(self.group_instance_id.as_deref()) }; }
81        if version >= 0 { n += if flex { compact_string_len(&self.protocol_type) } else { string_len(&self.protocol_type) }; }
82        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.protocols).len(), flex); let body: usize = (self.protocols).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
83        if version >= 8 { n += if flex { compact_nullable_string_len(self.reason.as_deref()) } else { nullable_string_len(self.reason.as_deref()) }; }
84        if flex {
85            let known_pairs: Vec<(u32, usize)> = Vec::new();
86            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
87        }
88        n
89    }
90}
91
92impl<'de> Decode<'de> for JoinGroupRequest {
93    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
94        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
95            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
96        }
97        let flex = is_flexible(version);
98        let mut out = Self::default();
99        if version >= 0 { out.group_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
100        if version >= 0 { out.session_timeout_ms = get_i32(buf)?; }
101        if version >= 1 { out.rebalance_timeout_ms = get_i32(buf)?; }
102        if version >= 0 { out.member_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
103        if version >= 5 { out.group_instance_id = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
104        if version >= 0 { out.protocol_type = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
105        if version >= 0 { out.protocols = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(JoinGroupRequestProtocol::decode(buf, version)?); } v }; }
106        if version >= 8 { out.reason = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
107        if flex {
108            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
109                Ok(false)
110            })?;
111        }
112        Ok(out)
113    }
114}
115
116#[derive(Debug, Clone, PartialEq, Eq, Default)]
117pub struct JoinGroupRequestProtocol {
118    pub name: String,
119    pub metadata: ::bytes::Bytes,
120    pub unknown_tagged_fields: UnknownTaggedFields,
121}
122
123impl Encode for JoinGroupRequestProtocol {
124    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
125        let flex = version >= 6;
126        if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
127        if version >= 0 { if flex { put_compact_bytes(buf, &self.metadata) } else { put_bytes(buf, &self.metadata) } }
128        if flex {
129            let tagged = WriteTaggedFields::new();
130            tagged.write(buf, &self.unknown_tagged_fields);
131        }
132        Ok(())
133    }
134    fn encoded_len(&self, version: i16) -> usize {
135        let flex = version >= 6;
136        let mut n: usize = 0;
137        if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
138        if version >= 0 { n += if flex { compact_bytes_len(&self.metadata) } else { bytes_len(&self.metadata) }; }
139        if flex {
140            let known_pairs: Vec<(u32, usize)> = Vec::new();
141            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
142        }
143        n
144    }
145}
146
147impl<'de> Decode<'de> for JoinGroupRequestProtocol {
148    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
149        let flex = version >= 6;
150        let mut out = Self::default();
151        if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
152        if version >= 0 { out.metadata = if flex { get_compact_bytes_owned(buf)? } else { get_bytes_owned(buf)? }; }
153        if flex {
154            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
155                Ok(false)
156            })?;
157        }
158        Ok(out)
159    }
160}
161
162/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
163/// Only includes fields valid for the given version.
164#[must_use]
165#[allow(unused_comparisons)]
166pub fn default_json(version: i16) -> ::serde_json::Value {
167    let mut obj = ::serde_json::Map::new();
168    obj.insert("groupId".to_string(), ::serde_json::Value::String(String::new()));
169    obj.insert("sessionTimeoutMs".to_string(), ::serde_json::json!(0));
170    if version >= 1 {
171        obj.insert("rebalanceTimeoutMs".to_string(), ::serde_json::json!(-1));
172    }
173    obj.insert("memberId".to_string(), ::serde_json::Value::String(String::new()));
174    if version >= 5 {
175        obj.insert("groupInstanceId".to_string(), ::serde_json::Value::Null);
176    }
177    obj.insert("protocolType".to_string(), ::serde_json::Value::String(String::new()));
178    obj.insert("protocols".to_string(), ::serde_json::Value::Array(vec![]));
179    if version >= 8 {
180        obj.insert("reason".to_string(), ::serde_json::Value::Null);
181    }
182    ::serde_json::Value::Object(obj)
183}
184
185impl crate::ProtocolRequest for JoinGroupRequest {
186    const API_KEY: i16 = API_KEY;
187    const MIN_VERSION: i16 = MIN_VERSION;
188    const MAX_VERSION: i16 = MAX_VERSION;
189    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
190    type Response = super::join_group_response::JoinGroupResponse;
191}