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