Skip to main content

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