Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
JoinGroupResponse.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_bool, get_i16, get_i32, put_bool, 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 = 11;
21pub const MIN_VERSION: i16 = 0;
22pub const MAX_VERSION: i16 = 9;
23pub const FLEXIBLE_MIN: i16 = 6;
24
25#[inline]
26fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
27
28#[derive(Debug, Clone, PartialEq, Eq)]
29pub struct JoinGroupResponse<'a> {
30    pub throttle_time_ms: i32,
31    pub error_code: i16,
32    pub generation_id: i32,
33    pub protocol_type: Option<&'a str>,
34    pub protocol_name: Option<&'a str>,
35    pub leader: &'a str,
36    pub skip_assignment: bool,
37    pub member_id: &'a str,
38    pub members: Vec<JoinGroupResponseMember<'a>>,
39    pub unknown_tagged_fields: UnknownTaggedFields,
40}
41
42impl<'a> Default for JoinGroupResponse<'a> {
43    fn default() -> Self {
44        Self {
45            throttle_time_ms: 0i32,
46            error_code: 0i16,
47            generation_id: -1i32,
48            protocol_type: None,
49            protocol_name: None,
50            leader: "",
51            skip_assignment: false,
52            member_id: "",
53            members: Vec::new(),
54            unknown_tagged_fields: Default::default(),
55        }
56    }
57}
58
59impl<'a> JoinGroupResponse<'a> {
60    pub fn to_owned(&self) -> crate::owned::join_group_response::JoinGroupResponse {
61        crate::owned::join_group_response::JoinGroupResponse {
62            throttle_time_ms: (self.throttle_time_ms),
63            error_code: (self.error_code),
64            generation_id: (self.generation_id),
65            protocol_type: (self.protocol_type).map(|s| s.to_string()),
66            protocol_name: (self.protocol_name).map(|s| s.to_string()),
67            leader: (self.leader).to_string(),
68            skip_assignment: (self.skip_assignment),
69            member_id: (self.member_id).to_string(),
70            members: (self.members).iter().map(|it| it.to_owned()).collect(),
71            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
72        }
73    }
74}
75
76impl<'a> Encode for JoinGroupResponse<'a> {
77    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
78        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
79            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
80        }
81        let flex = is_flexible(version);
82        if version >= 2 { put_i32(buf, self.throttle_time_ms) }
83        if version >= 0 { put_i16(buf, self.error_code) }
84        if version >= 0 { put_i32(buf, self.generation_id) }
85        if version >= 7 { if flex { put_compact_nullable_string(buf, self.protocol_type) } else { put_nullable_string(buf, self.protocol_type) } }
86        if version >= 0 { if version >= 7 { if flex { put_compact_nullable_string(buf, self.protocol_name) } else { put_nullable_string(buf, self.protocol_name) } } else { if flex { put_compact_string(buf, (self.protocol_name).unwrap_or("")) } else { put_string(buf, (self.protocol_name).unwrap_or("")) } } }
87        if version >= 0 { if flex { put_compact_string(buf, self.leader) } else { put_string(buf, self.leader) } }
88        if version >= 9 { put_bool(buf, self.skip_assignment) }
89        if version >= 0 { if flex { put_compact_string(buf, self.member_id) } else { put_string(buf, self.member_id) } }
90        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.members).len(), flex); for it in &self.members { it.encode(buf, version)?; } } }
91        if flex {
92            let tagged = WriteTaggedFields::new();
93            tagged.write(buf, &self.unknown_tagged_fields);
94        }
95        Ok(())
96    }
97    fn encoded_len(&self, version: i16) -> usize {
98        let flex = is_flexible(version);
99        let mut n: usize = 0;
100        if version >= 2 { n += 4; }
101        if version >= 0 { n += 2; }
102        if version >= 0 { n += 4; }
103        if version >= 7 { n += if flex { compact_nullable_string_len(self.protocol_type) } else { nullable_string_len(self.protocol_type) }; }
104        if version >= 0 { n += if version >= 7 { if flex { compact_nullable_string_len(self.protocol_name) } else { nullable_string_len(self.protocol_name) } } else { if flex { compact_string_len((self.protocol_name).unwrap_or("")) } else { string_len((self.protocol_name).unwrap_or("")) } }; }
105        if version >= 0 { n += if flex { compact_string_len(self.leader) } else { string_len(self.leader) }; }
106        if version >= 9 { n += 1; }
107        if version >= 0 { n += if flex { compact_string_len(self.member_id) } else { string_len(self.member_id) }; }
108        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 }; }
109        if flex {
110            let known_pairs: Vec<(u32, usize)> = Vec::new();
111            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
112        }
113        n
114    }
115}
116
117impl<'de> DecodeBorrow<'de> for JoinGroupResponse<'de> {
118    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
119        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
120            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
121        }
122        let flex = is_flexible(version);
123        let mut out = Self::default();
124        if version >= 2 { out.throttle_time_ms = get_i32(buf)?; }
125        if version >= 0 { out.error_code = get_i16(buf)?; }
126        if version >= 0 { out.generation_id = get_i32(buf)?; }
127        if version >= 7 { out.protocol_type = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
128        if version >= 0 { out.protocol_name = if version >= 7 { if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? } } else { Some(if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }) }; }
129        if version >= 0 { out.leader = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
130        if version >= 9 { out.skip_assignment = get_bool(buf)?; }
131        if version >= 0 { out.member_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
132        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(JoinGroupResponseMember::decode_borrow(buf, version)?); } v }; }
133        if flex {
134            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
135                Ok(false)
136            })?;
137        }
138        Ok(out)
139    }
140}
141
142#[derive(Debug, Clone, PartialEq, Eq)]
143pub struct JoinGroupResponseMember<'a> {
144    pub member_id: &'a str,
145    pub group_instance_id: Option<&'a str>,
146    pub metadata: &'a [u8],
147    pub unknown_tagged_fields: UnknownTaggedFields,
148}
149
150impl<'a> Default for JoinGroupResponseMember<'a> {
151    fn default() -> Self {
152        Self {
153            member_id: "",
154            group_instance_id: None,
155            metadata: &[],
156            unknown_tagged_fields: Default::default(),
157        }
158    }
159}
160
161impl<'a> JoinGroupResponseMember<'a> {
162    pub fn to_owned(&self) -> crate::owned::join_group_response::JoinGroupResponseMember {
163        crate::owned::join_group_response::JoinGroupResponseMember {
164            member_id: (self.member_id).to_string(),
165            group_instance_id: (self.group_instance_id).map(|s| s.to_string()),
166            metadata: Bytes::copy_from_slice(self.metadata),
167            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
168        }
169    }
170}
171
172impl<'a> Encode for JoinGroupResponseMember<'a> {
173    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
174        let flex = version >= 6;
175        if version >= 0 { if flex { put_compact_string(buf, self.member_id) } else { put_string(buf, self.member_id) } }
176        if version >= 5 { if flex { put_compact_nullable_string(buf, self.group_instance_id) } else { put_nullable_string(buf, self.group_instance_id) } }
177        if version >= 0 { if flex { put_compact_bytes(buf, self.metadata) } else { put_bytes(buf, self.metadata) } }
178        if flex {
179            let tagged = WriteTaggedFields::new();
180            tagged.write(buf, &self.unknown_tagged_fields);
181        }
182        Ok(())
183    }
184    fn encoded_len(&self, version: i16) -> usize {
185        let flex = version >= 6;
186        let mut n: usize = 0;
187        if version >= 0 { n += if flex { compact_string_len(self.member_id) } else { string_len(self.member_id) }; }
188        if version >= 5 { n += if flex { compact_nullable_string_len(self.group_instance_id) } else { nullable_string_len(self.group_instance_id) }; }
189        if version >= 0 { n += if flex { crate::primitives::varint::uvarint_len(u32::try_from((self.metadata).len() + 1).unwrap()) + (self.metadata).len() } else { 4 + (self.metadata).len() }; }
190        if flex {
191            let known_pairs: Vec<(u32, usize)> = Vec::new();
192            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
193        }
194        n
195    }
196}
197
198impl<'de> DecodeBorrow<'de> for JoinGroupResponseMember<'de> {
199    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
200        let flex = version >= 6;
201        let mut out = Self::default();
202        if version >= 0 { out.member_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
203        if version >= 5 { out.group_instance_id = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
204        if version >= 0 { out.metadata = if flex { get_compact_bytes_borrowed(buf)? } else { get_bytes_borrowed(buf)? }; }
205        if flex {
206            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
207                Ok(false)
208            })?;
209        }
210        Ok(out)
211    }
212}