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