Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeGroupsResponse.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_i16, get_i32, put_i16, 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 = 15;
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 6;
19pub const FLEXIBLE_MIN: i16 = 5;
20
21#[inline]
22fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
23
24#[derive(Debug, Clone, PartialEq, Eq, Default)]
25pub struct DescribeGroupsResponse {
26    pub throttle_time_ms: i32,
27    pub groups: Vec<DescribedGroup>,
28    pub unknown_tagged_fields: UnknownTaggedFields,
29}
30
31impl Encode for DescribeGroupsResponse {
32    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
33        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
34            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
35        }
36        let flex = is_flexible(version);
37        if version >= 1 { put_i32(buf, self.throttle_time_ms) }
38        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.groups).len(), flex); for it in &self.groups { it.encode(buf, version)?; } } }
39        if flex {
40            let tagged = WriteTaggedFields::new();
41            tagged.write(buf, &self.unknown_tagged_fields);
42        }
43        Ok(())
44    }
45    fn encoded_len(&self, version: i16) -> usize {
46        let flex = is_flexible(version);
47        let mut n: usize = 0;
48        if version >= 1 { n += 4; }
49        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.groups).len(), flex); let body: usize = (self.groups).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
50        if flex {
51            let known_pairs: Vec<(u32, usize)> = Vec::new();
52            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
53        }
54        n
55    }
56}
57
58impl<'de> Decode<'de> for DescribeGroupsResponse {
59    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
60        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
61            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
62        }
63        let flex = is_flexible(version);
64        let mut out = Self::default();
65        if version >= 1 { out.throttle_time_ms = get_i32(buf)?; }
66        if version >= 0 { out.groups = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DescribedGroup::decode(buf, version)?); } v }; }
67        if flex {
68            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
69                Ok(false)
70            })?;
71        }
72        Ok(out)
73    }
74}
75
76#[derive(Debug, Clone, PartialEq, Eq)]
77pub struct DescribedGroup {
78    pub error_code: i16,
79    pub error_message: Option<String>,
80    pub group_id: String,
81    pub group_state: String,
82    pub protocol_type: String,
83    pub protocol_data: String,
84    pub members: Vec<DescribedGroupMember>,
85    pub authorized_operations: i32,
86    pub unknown_tagged_fields: UnknownTaggedFields,
87}
88
89impl Default for DescribedGroup {
90    fn default() -> Self {
91        Self {
92            error_code: 0i16,
93            error_message: None,
94            group_id: String::new(),
95            group_state: String::new(),
96            protocol_type: String::new(),
97            protocol_data: String::new(),
98            members: Vec::new(),
99            authorized_operations: -2_147_483_648i32,
100            unknown_tagged_fields: Default::default(),
101        }
102    }
103}
104
105impl Encode for DescribedGroup {
106    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
107        let flex = version >= 5;
108        if version >= 0 { put_i16(buf, self.error_code) }
109        if version >= 6 { if flex { put_compact_nullable_string(buf, self.error_message.as_deref()) } else { put_nullable_string(buf, self.error_message.as_deref()) } }
110        if version >= 0 { if flex { put_compact_string(buf, &self.group_id) } else { put_string(buf, &self.group_id) } }
111        if version >= 0 { if flex { put_compact_string(buf, &self.group_state) } else { put_string(buf, &self.group_state) } }
112        if version >= 0 { if flex { put_compact_string(buf, &self.protocol_type) } else { put_string(buf, &self.protocol_type) } }
113        if version >= 0 { if flex { put_compact_string(buf, &self.protocol_data) } else { put_string(buf, &self.protocol_data) } }
114        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.members).len(), flex); for it in &self.members { it.encode(buf, version)?; } } }
115        if version >= 3 { put_i32(buf, self.authorized_operations) }
116        if flex {
117            let tagged = WriteTaggedFields::new();
118            tagged.write(buf, &self.unknown_tagged_fields);
119        }
120        Ok(())
121    }
122    fn encoded_len(&self, version: i16) -> usize {
123        let flex = version >= 5;
124        let mut n: usize = 0;
125        if version >= 0 { n += 2; }
126        if version >= 6 { n += if flex { compact_nullable_string_len(self.error_message.as_deref()) } else { nullable_string_len(self.error_message.as_deref()) }; }
127        if version >= 0 { n += if flex { compact_string_len(&self.group_id) } else { string_len(&self.group_id) }; }
128        if version >= 0 { n += if flex { compact_string_len(&self.group_state) } else { string_len(&self.group_state) }; }
129        if version >= 0 { n += if flex { compact_string_len(&self.protocol_type) } else { string_len(&self.protocol_type) }; }
130        if version >= 0 { n += if flex { compact_string_len(&self.protocol_data) } else { string_len(&self.protocol_data) }; }
131        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.members).len(), flex); let body: usize = (self.members).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
132        if version >= 3 { n += 4; }
133        if flex {
134            let known_pairs: Vec<(u32, usize)> = Vec::new();
135            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
136        }
137        n
138    }
139}
140
141impl<'de> Decode<'de> for DescribedGroup {
142    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
143        let flex = version >= 5;
144        let mut out = Self::default();
145        if version >= 0 { out.error_code = get_i16(buf)?; }
146        if version >= 6 { out.error_message = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
147        if version >= 0 { out.group_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
148        if version >= 0 { out.group_state = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
149        if version >= 0 { out.protocol_type = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
150        if version >= 0 { out.protocol_data = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
151        if version >= 0 { out.members = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DescribedGroupMember::decode(buf, version)?); } v }; }
152        if version >= 3 { out.authorized_operations = get_i32(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#[derive(Debug, Clone, PartialEq, Eq, Default)]
163pub struct DescribedGroupMember {
164    pub member_id: String,
165    pub group_instance_id: Option<String>,
166    pub client_id: String,
167    pub client_host: String,
168    pub member_metadata: ::bytes::Bytes,
169    pub member_assignment: ::bytes::Bytes,
170    pub unknown_tagged_fields: UnknownTaggedFields,
171}
172
173impl Encode for DescribedGroupMember {
174    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
175        let flex = version >= 5;
176        if version >= 0 { if flex { put_compact_string(buf, &self.member_id) } else { put_string(buf, &self.member_id) } }
177        if version >= 4 { if flex { put_compact_nullable_string(buf, self.group_instance_id.as_deref()) } else { put_nullable_string(buf, self.group_instance_id.as_deref()) } }
178        if version >= 0 { if flex { put_compact_string(buf, &self.client_id) } else { put_string(buf, &self.client_id) } }
179        if version >= 0 { if flex { put_compact_string(buf, &self.client_host) } else { put_string(buf, &self.client_host) } }
180        if version >= 0 { if flex { put_compact_bytes(buf, &self.member_metadata) } else { put_bytes(buf, &self.member_metadata) } }
181        if version >= 0 { if flex { put_compact_bytes(buf, &self.member_assignment) } else { put_bytes(buf, &self.member_assignment) } }
182        if flex {
183            let tagged = WriteTaggedFields::new();
184            tagged.write(buf, &self.unknown_tagged_fields);
185        }
186        Ok(())
187    }
188    fn encoded_len(&self, version: i16) -> usize {
189        let flex = version >= 5;
190        let mut n: usize = 0;
191        if version >= 0 { n += if flex { compact_string_len(&self.member_id) } else { string_len(&self.member_id) }; }
192        if version >= 4 { n += if flex { compact_nullable_string_len(self.group_instance_id.as_deref()) } else { nullable_string_len(self.group_instance_id.as_deref()) }; }
193        if version >= 0 { n += if flex { compact_string_len(&self.client_id) } else { string_len(&self.client_id) }; }
194        if version >= 0 { n += if flex { compact_string_len(&self.client_host) } else { string_len(&self.client_host) }; }
195        if version >= 0 { n += if flex { compact_bytes_len(&self.member_metadata) } else { bytes_len(&self.member_metadata) }; }
196        if version >= 0 { n += if flex { compact_bytes_len(&self.member_assignment) } else { bytes_len(&self.member_assignment) }; }
197        if flex {
198            let known_pairs: Vec<(u32, usize)> = Vec::new();
199            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
200        }
201        n
202    }
203}
204
205impl<'de> Decode<'de> for DescribedGroupMember {
206    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
207        let flex = version >= 5;
208        let mut out = Self::default();
209        if version >= 0 { out.member_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
210        if version >= 4 { out.group_instance_id = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
211        if version >= 0 { out.client_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
212        if version >= 0 { out.client_host = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
213        if version >= 0 { out.member_metadata = if flex { get_compact_bytes_owned(buf)? } else { get_bytes_owned(buf)? }; }
214        if version >= 0 { out.member_assignment = if flex { get_compact_bytes_owned(buf)? } else { get_bytes_owned(buf)? }; }
215        if flex {
216            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
217                Ok(false)
218            })?;
219        }
220        Ok(out)
221    }
222}
223
224/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
225/// Only includes fields valid for the given version.
226#[must_use]
227#[allow(unused_comparisons)]
228pub fn default_json(version: i16) -> ::serde_json::Value {
229    let mut obj = ::serde_json::Map::new();
230    if version >= 1 {
231        obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
232    }
233    obj.insert("groups".to_string(), ::serde_json::Value::Array(vec![]));
234    ::serde_json::Value::Object(obj)
235}