Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeGroupsResponse.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Bytes, 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, nullable_string_len,
8    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
9    string_len,
10};
11use crate::primitives::string_bytes_borrowed::{
12    get_compact_nullable_string_borrowed, get_compact_string_borrowed,
13    get_nullable_string_borrowed, get_string_borrowed,
14};
15use crate::primitives::string_bytes::{put_bytes, put_compact_bytes};
16use crate::primitives::string_bytes_borrowed::{get_bytes_borrowed, get_compact_bytes_borrowed};
17use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
18use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
19
20pub const API_KEY: i16 = 15;
21pub const MIN_VERSION: i16 = 0;
22pub const MAX_VERSION: i16 = 6;
23pub const FLEXIBLE_MIN: i16 = 5;
24
25#[inline]
26fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
27
28#[derive(Debug, Clone, PartialEq, Eq)]
29pub struct DescribeGroupsResponse<'a> {
30    pub throttle_time_ms: i32,
31    pub groups: Vec<DescribedGroup<'a>>,
32    pub unknown_tagged_fields: UnknownTaggedFields,
33}
34
35impl<'a> Default for DescribeGroupsResponse<'a> {
36    fn default() -> Self {
37        Self {
38            throttle_time_ms: 0i32,
39            groups: Vec::new(),
40            unknown_tagged_fields: Default::default(),
41        }
42    }
43}
44
45impl<'a> DescribeGroupsResponse<'a> {
46    pub fn to_owned(&self) -> crate::owned::describe_groups_response::DescribeGroupsResponse {
47        crate::owned::describe_groups_response::DescribeGroupsResponse {
48            throttle_time_ms: (self.throttle_time_ms),
49            groups: (self.groups).iter().map(|it| it.to_owned()).collect(),
50            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
51        }
52    }
53}
54
55impl<'a> Encode for DescribeGroupsResponse<'a> {
56    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
57        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
58            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
59        }
60        let flex = is_flexible(version);
61        if version >= 1 { put_i32(buf, self.throttle_time_ms) }
62        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.groups).len(), flex); for it in &self.groups { it.encode(buf, version)?; } } }
63        if flex {
64            let tagged = WriteTaggedFields::new();
65            tagged.write(buf, &self.unknown_tagged_fields);
66        }
67        Ok(())
68    }
69    fn encoded_len(&self, version: i16) -> usize {
70        let flex = is_flexible(version);
71        let mut n: usize = 0;
72        if version >= 1 { n += 4; }
73        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 }; }
74        if flex {
75            let known_pairs: Vec<(u32, usize)> = Vec::new();
76            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
77        }
78        n
79    }
80}
81
82impl<'de> DecodeBorrow<'de> for DescribeGroupsResponse<'de> {
83    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
84        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
85            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
86        }
87        let flex = is_flexible(version);
88        let mut out = Self::default();
89        if version >= 1 { out.throttle_time_ms = get_i32(buf)?; }
90        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_borrow(buf, version)?); } v }; }
91        if flex {
92            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
93                Ok(false)
94            })?;
95        }
96        Ok(out)
97    }
98}
99
100#[derive(Debug, Clone, PartialEq, Eq)]
101pub struct DescribedGroup<'a> {
102    pub error_code: i16,
103    pub error_message: Option<&'a str>,
104    pub group_id: &'a str,
105    pub group_state: &'a str,
106    pub protocol_type: &'a str,
107    pub protocol_data: &'a str,
108    pub members: Vec<DescribedGroupMember<'a>>,
109    pub authorized_operations: i32,
110    pub unknown_tagged_fields: UnknownTaggedFields,
111}
112
113impl<'a> Default for DescribedGroup<'a> {
114    fn default() -> Self {
115        Self {
116            error_code: 0i16,
117            error_message: None,
118            group_id: "",
119            group_state: "",
120            protocol_type: "",
121            protocol_data: "",
122            members: Vec::new(),
123            authorized_operations: -2_147_483_648i32,
124            unknown_tagged_fields: Default::default(),
125        }
126    }
127}
128
129impl<'a> DescribedGroup<'a> {
130    pub fn to_owned(&self) -> crate::owned::describe_groups_response::DescribedGroup {
131        crate::owned::describe_groups_response::DescribedGroup {
132            error_code: (self.error_code),
133            error_message: (self.error_message).map(|s| s.to_string()),
134            group_id: (self.group_id).to_string(),
135            group_state: (self.group_state).to_string(),
136            protocol_type: (self.protocol_type).to_string(),
137            protocol_data: (self.protocol_data).to_string(),
138            members: (self.members).iter().map(|it| it.to_owned()).collect(),
139            authorized_operations: (self.authorized_operations),
140            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
141        }
142    }
143}
144
145impl<'a> Encode for DescribedGroup<'a> {
146    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
147        let flex = version >= 5;
148        if version >= 0 { put_i16(buf, self.error_code) }
149        if version >= 6 { if flex { put_compact_nullable_string(buf, self.error_message) } else { put_nullable_string(buf, self.error_message) } }
150        if version >= 0 { if flex { put_compact_string(buf, self.group_id) } else { put_string(buf, self.group_id) } }
151        if version >= 0 { if flex { put_compact_string(buf, self.group_state) } else { put_string(buf, self.group_state) } }
152        if version >= 0 { if flex { put_compact_string(buf, self.protocol_type) } else { put_string(buf, self.protocol_type) } }
153        if version >= 0 { if flex { put_compact_string(buf, self.protocol_data) } else { put_string(buf, self.protocol_data) } }
154        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.members).len(), flex); for it in &self.members { it.encode(buf, version)?; } } }
155        if version >= 3 { put_i32(buf, self.authorized_operations) }
156        if flex {
157            let tagged = WriteTaggedFields::new();
158            tagged.write(buf, &self.unknown_tagged_fields);
159        }
160        Ok(())
161    }
162    fn encoded_len(&self, version: i16) -> usize {
163        let flex = version >= 5;
164        let mut n: usize = 0;
165        if version >= 0 { n += 2; }
166        if version >= 6 { n += if flex { compact_nullable_string_len(self.error_message) } else { nullable_string_len(self.error_message) }; }
167        if version >= 0 { n += if flex { compact_string_len(self.group_id) } else { string_len(self.group_id) }; }
168        if version >= 0 { n += if flex { compact_string_len(self.group_state) } else { string_len(self.group_state) }; }
169        if version >= 0 { n += if flex { compact_string_len(self.protocol_type) } else { string_len(self.protocol_type) }; }
170        if version >= 0 { n += if flex { compact_string_len(self.protocol_data) } else { string_len(self.protocol_data) }; }
171        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 }; }
172        if version >= 3 { n += 4; }
173        if flex {
174            let known_pairs: Vec<(u32, usize)> = Vec::new();
175            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
176        }
177        n
178    }
179}
180
181impl<'de> DecodeBorrow<'de> for DescribedGroup<'de> {
182    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
183        let flex = version >= 5;
184        let mut out = Self::default();
185        if version >= 0 { out.error_code = get_i16(buf)?; }
186        if version >= 6 { out.error_message = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
187        if version >= 0 { out.group_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
188        if version >= 0 { out.group_state = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
189        if version >= 0 { out.protocol_type = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
190        if version >= 0 { out.protocol_data = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
191        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_borrow(buf, version)?); } v }; }
192        if version >= 3 { out.authorized_operations = get_i32(buf)?; }
193        if flex {
194            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
195                Ok(false)
196            })?;
197        }
198        Ok(out)
199    }
200}
201
202#[derive(Debug, Clone, PartialEq, Eq)]
203pub struct DescribedGroupMember<'a> {
204    pub member_id: &'a str,
205    pub group_instance_id: Option<&'a str>,
206    pub client_id: &'a str,
207    pub client_host: &'a str,
208    pub member_metadata: &'a [u8],
209    pub member_assignment: &'a [u8],
210    pub unknown_tagged_fields: UnknownTaggedFields,
211}
212
213impl<'a> Default for DescribedGroupMember<'a> {
214    fn default() -> Self {
215        Self {
216            member_id: "",
217            group_instance_id: None,
218            client_id: "",
219            client_host: "",
220            member_metadata: &[],
221            member_assignment: &[],
222            unknown_tagged_fields: Default::default(),
223        }
224    }
225}
226
227impl<'a> DescribedGroupMember<'a> {
228    pub fn to_owned(&self) -> crate::owned::describe_groups_response::DescribedGroupMember {
229        crate::owned::describe_groups_response::DescribedGroupMember {
230            member_id: (self.member_id).to_string(),
231            group_instance_id: (self.group_instance_id).map(|s| s.to_string()),
232            client_id: (self.client_id).to_string(),
233            client_host: (self.client_host).to_string(),
234            member_metadata: Bytes::copy_from_slice(self.member_metadata),
235            member_assignment: Bytes::copy_from_slice(self.member_assignment),
236            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
237        }
238    }
239}
240
241impl<'a> Encode for DescribedGroupMember<'a> {
242    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
243        let flex = version >= 5;
244        if version >= 0 { if flex { put_compact_string(buf, self.member_id) } else { put_string(buf, self.member_id) } }
245        if version >= 4 { if flex { put_compact_nullable_string(buf, self.group_instance_id) } else { put_nullable_string(buf, self.group_instance_id) } }
246        if version >= 0 { if flex { put_compact_string(buf, self.client_id) } else { put_string(buf, self.client_id) } }
247        if version >= 0 { if flex { put_compact_string(buf, self.client_host) } else { put_string(buf, self.client_host) } }
248        if version >= 0 { if flex { put_compact_bytes(buf, self.member_metadata) } else { put_bytes(buf, self.member_metadata) } }
249        if version >= 0 { if flex { put_compact_bytes(buf, self.member_assignment) } else { put_bytes(buf, self.member_assignment) } }
250        if flex {
251            let tagged = WriteTaggedFields::new();
252            tagged.write(buf, &self.unknown_tagged_fields);
253        }
254        Ok(())
255    }
256    fn encoded_len(&self, version: i16) -> usize {
257        let flex = version >= 5;
258        let mut n: usize = 0;
259        if version >= 0 { n += if flex { compact_string_len(self.member_id) } else { string_len(self.member_id) }; }
260        if version >= 4 { n += if flex { compact_nullable_string_len(self.group_instance_id) } else { nullable_string_len(self.group_instance_id) }; }
261        if version >= 0 { n += if flex { compact_string_len(self.client_id) } else { string_len(self.client_id) }; }
262        if version >= 0 { n += if flex { compact_string_len(self.client_host) } else { string_len(self.client_host) }; }
263        if version >= 0 { n += if flex { crate::primitives::varint::uvarint_len(u32::try_from((self.member_metadata).len() + 1).unwrap()) + (self.member_metadata).len() } else { 4 + (self.member_metadata).len() }; }
264        if version >= 0 { n += if flex { crate::primitives::varint::uvarint_len(u32::try_from((self.member_assignment).len() + 1).unwrap()) + (self.member_assignment).len() } else { 4 + (self.member_assignment).len() }; }
265        if flex {
266            let known_pairs: Vec<(u32, usize)> = Vec::new();
267            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
268        }
269        n
270    }
271}
272
273impl<'de> DecodeBorrow<'de> for DescribedGroupMember<'de> {
274    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
275        let flex = version >= 5;
276        let mut out = Self::default();
277        if version >= 0 { out.member_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
278        if version >= 4 { out.group_instance_id = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
279        if version >= 0 { out.client_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
280        if version >= 0 { out.client_host = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
281        if version >= 0 { out.member_metadata = if flex { get_compact_bytes_borrowed(buf)? } else { get_bytes_borrowed(buf)? }; }
282        if version >= 0 { out.member_assignment = if flex { get_compact_bytes_borrowed(buf)? } else { get_bytes_borrowed(buf)? }; }
283        if flex {
284            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
285                Ok(false)
286            })?;
287        }
288        Ok(out)
289    }
290}