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