crabka_protocol/opt/rustwide/workdir/generated/
AlterShareGroupOffsetsResponse.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 = 91;
15pub const MIN_VERSION: i16 = 0;
16pub const MAX_VERSION: i16 = 0;
17pub const FLEXIBLE_MIN: i16 = 0;
18
19#[inline]
20fn is_flexible(version: i16) -> bool {
21 version >= FLEXIBLE_MIN
22}
23
24#[derive(Debug, Clone, PartialEq, Eq, Default)]
25pub struct AlterShareGroupOffsetsResponse {
26 pub throttle_time_ms: i32,
27 pub error_code: i16,
28 pub error_message: Option<String>,
29 pub responses: Vec<AlterShareGroupOffsetsResponseTopic>,
30 pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl Encode for AlterShareGroupOffsetsResponse {
33 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
34 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
35 return Err(ProtocolError::UnsupportedVersion {
36 api_key: API_KEY,
37 version,
38 });
39 }
40 let flex = is_flexible(version);
41 if version >= 0 {
42 put_i32(buf, self.throttle_time_ms);
43 }
44 if version >= 0 {
45 put_i16(buf, self.error_code);
46 }
47 if version >= 0 {
48 if flex {
49 put_compact_nullable_string(buf, self.error_message.as_deref());
50 } else {
51 put_nullable_string(buf, self.error_message.as_deref());
52 }
53 }
54 if version >= 0 {
55 {
56 crate::primitives::array::put_array_len(buf, (self.responses).len(), flex);
57 for it in &self.responses {
58 it.encode(buf, version)?;
59 }
60 }
61 }
62 if flex {
63 let tagged = WriteTaggedFields::new();
64 tagged.write(buf, &self.unknown_tagged_fields);
65 }
66 Ok(())
67 }
68 fn encoded_len(&self, version: i16) -> usize {
69 let flex = is_flexible(version);
70 let mut n: usize = 0;
71 if version >= 0 {
72 n += 4;
73 }
74 if version >= 0 {
75 n += 2;
76 }
77 if version >= 0 {
78 n += if flex {
79 compact_nullable_string_len(self.error_message.as_deref())
80 } else {
81 nullable_string_len(self.error_message.as_deref())
82 };
83 }
84 if version >= 0 {
85 n += {
86 let prefix =
87 crate::primitives::array::array_len_prefix_len((self.responses).len(), flex);
88 let body: usize = (self.responses)
89 .iter()
90 .map(|it| it.encoded_len(version))
91 .sum();
92 prefix + body
93 };
94 }
95 if flex {
96 let known_pairs: Vec<(u32, usize)> = Vec::new();
97 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
98 }
99 n
100 }
101}
102impl Decode<'_> for AlterShareGroupOffsetsResponse {
103 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
104 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
105 return Err(ProtocolError::UnsupportedVersion {
106 api_key: API_KEY,
107 version,
108 });
109 }
110 let flex = is_flexible(version);
111 let mut out = Self::default();
112 if version >= 0 {
113 out.throttle_time_ms = get_i32(buf)?;
114 }
115 if version >= 0 {
116 out.error_code = get_i16(buf)?;
117 }
118 if version >= 0 {
119 out.error_message = if flex {
120 get_compact_nullable_string_owned(buf)?
121 } else {
122 get_nullable_string_owned(buf)?
123 };
124 }
125 if version >= 0 {
126 out.responses = {
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(AlterShareGroupOffsetsResponseTopic::decode(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 AlterShareGroupOffsetsResponse {
143 #[must_use]
144 pub fn populated(version: i16) -> Self {
145 let mut m = Self::default();
146 if version >= 0 {
147 m.throttle_time_ms = 1i32;
148 }
149 if version >= 0 {
150 m.error_code = 1i16;
151 }
152 if version >= 0 {
153 m.error_message = Some("x".to_string());
154 }
155 if version >= 0 {
156 m.responses = vec![AlterShareGroupOffsetsResponseTopic::populated(version)];
157 }
158 m
159 }
160}
161#[derive(Debug, Clone, PartialEq, Eq, Default)]
162pub struct AlterShareGroupOffsetsResponseTopic {
163 pub topic_name: String,
164 pub topic_id: crate::primitives::uuid::Uuid,
165 pub partitions: Vec<AlterShareGroupOffsetsResponsePartition>,
166 pub unknown_tagged_fields: UnknownTaggedFields,
167}
168impl Encode for AlterShareGroupOffsetsResponseTopic {
169 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
170 let flex = version >= 0;
171 if version >= 0 {
172 if flex {
173 put_compact_string(buf, &self.topic_name);
174 } else {
175 put_string(buf, &self.topic_name);
176 }
177 }
178 if version >= 0 {
179 crate::primitives::uuid::put_uuid(buf, self.topic_id);
180 }
181 if version >= 0 {
182 {
183 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
184 for it in &self.partitions {
185 it.encode(buf, version)?;
186 }
187 }
188 }
189 if flex {
190 let tagged = WriteTaggedFields::new();
191 tagged.write(buf, &self.unknown_tagged_fields);
192 }
193 Ok(())
194 }
195 fn encoded_len(&self, version: i16) -> usize {
196 let flex = version >= 0;
197 let mut n: usize = 0;
198 if version >= 0 {
199 n += if flex {
200 compact_string_len(&self.topic_name)
201 } else {
202 string_len(&self.topic_name)
203 };
204 }
205 if version >= 0 {
206 n += 16;
207 }
208 if version >= 0 {
209 n += {
210 let prefix =
211 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
212 let body: usize = (self.partitions)
213 .iter()
214 .map(|it| it.encoded_len(version))
215 .sum();
216 prefix + body
217 };
218 }
219 if flex {
220 let known_pairs: Vec<(u32, usize)> = Vec::new();
221 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
222 }
223 n
224 }
225}
226impl Decode<'_> for AlterShareGroupOffsetsResponseTopic {
227 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
228 let flex = version >= 0;
229 let mut out = Self::default();
230 if version >= 0 {
231 out.topic_name = if flex {
232 get_compact_string_owned(buf)?
233 } else {
234 get_string_owned(buf)?
235 };
236 }
237 if version >= 0 {
238 out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
239 }
240 if version >= 0 {
241 out.partitions = {
242 let n = crate::primitives::array::get_array_len(buf, flex)?;
243 let mut v = Vec::with_capacity(n);
244 for _ in 0..n {
245 v.push(AlterShareGroupOffsetsResponsePartition::decode(
246 buf, version,
247 )?);
248 }
249 v
250 };
251 }
252 if flex {
253 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
254 }
255 Ok(out)
256 }
257}
258#[cfg(test)]
259impl AlterShareGroupOffsetsResponseTopic {
260 #[must_use]
261 pub fn populated(version: i16) -> Self {
262 let mut m = Self::default();
263 if version >= 0 {
264 m.topic_name = "x".to_string();
265 }
266 if version >= 0 {
267 m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
268 }
269 if version >= 0 {
270 m.partitions = vec![AlterShareGroupOffsetsResponsePartition::populated(version)];
271 }
272 m
273 }
274}
275#[derive(Debug, Clone, PartialEq, Eq, Default)]
276pub struct AlterShareGroupOffsetsResponsePartition {
277 pub partition_index: i32,
278 pub error_code: i16,
279 pub error_message: Option<String>,
280 pub unknown_tagged_fields: UnknownTaggedFields,
281}
282impl Encode for AlterShareGroupOffsetsResponsePartition {
283 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
284 let flex = version >= 0;
285 if version >= 0 {
286 put_i32(buf, self.partition_index);
287 }
288 if version >= 0 {
289 put_i16(buf, self.error_code);
290 }
291 if version >= 0 {
292 if flex {
293 put_compact_nullable_string(buf, self.error_message.as_deref());
294 } else {
295 put_nullable_string(buf, self.error_message.as_deref());
296 }
297 }
298 if flex {
299 let tagged = WriteTaggedFields::new();
300 tagged.write(buf, &self.unknown_tagged_fields);
301 }
302 Ok(())
303 }
304 fn encoded_len(&self, version: i16) -> usize {
305 let flex = version >= 0;
306 let mut n: usize = 0;
307 if version >= 0 {
308 n += 4;
309 }
310 if version >= 0 {
311 n += 2;
312 }
313 if version >= 0 {
314 n += if flex {
315 compact_nullable_string_len(self.error_message.as_deref())
316 } else {
317 nullable_string_len(self.error_message.as_deref())
318 };
319 }
320 if flex {
321 let known_pairs: Vec<(u32, usize)> = Vec::new();
322 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
323 }
324 n
325 }
326}
327impl Decode<'_> for AlterShareGroupOffsetsResponsePartition {
328 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
329 let flex = version >= 0;
330 let mut out = Self::default();
331 if version >= 0 {
332 out.partition_index = get_i32(buf)?;
333 }
334 if version >= 0 {
335 out.error_code = get_i16(buf)?;
336 }
337 if version >= 0 {
338 out.error_message = if flex {
339 get_compact_nullable_string_owned(buf)?
340 } else {
341 get_nullable_string_owned(buf)?
342 };
343 }
344 if flex {
345 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
346 }
347 Ok(out)
348 }
349}
350#[cfg(test)]
351impl AlterShareGroupOffsetsResponsePartition {
352 #[must_use]
353 pub fn populated(version: i16) -> Self {
354 let mut m = Self::default();
355 if version >= 0 {
356 m.partition_index = 1i32;
357 }
358 if version >= 0 {
359 m.error_code = 1i16;
360 }
361 if version >= 0 {
362 m.error_message = Some("x".to_string());
363 }
364 m
365 }
366}
367
368#[must_use]
371#[allow(unused_comparisons)]
372pub fn default_json(version: i16) -> ::serde_json::Value {
373 let mut obj = ::serde_json::Map::new();
374 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
375 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
376 obj.insert("errorMessage".to_string(), ::serde_json::Value::Null);
377 obj.insert("responses".to_string(), ::serde_json::Value::Array(vec![]));
378 ::serde_json::Value::Object(obj)
379}