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