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