Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
LeaveGroupResponse.borrowed.rs

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