crabka_protocol/opt/rustwide/workdir/generated/
ReadShareGroupStateResponse.owned.rs1use crate::primitives::fixed::{
4 get_i8, get_i16, get_i32, get_i64, put_i8, put_i16, put_i32, put_i64,
5};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, get_compact_nullable_string_owned, get_nullable_string_owned,
8 nullable_string_len, put_compact_nullable_string, put_nullable_string,
9};
10use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12use bytes::{Buf, BufMut};
13pub const API_KEY: i16 = 84;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 0;
16pub const FLEXIBLE_MIN: i16 = 0;
17#[inline]
18fn is_flexible(version: i16) -> bool {
19 version >= FLEXIBLE_MIN
20}
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct ReadShareGroupStateResponse {
23 pub results: Vec<ReadStateResult>,
24 pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl Encode for ReadShareGroupStateResponse {
27 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
28 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
29 return Err(ProtocolError::UnsupportedVersion {
30 api_key: API_KEY,
31 version,
32 });
33 }
34 let flex = is_flexible(version);
35 if version >= 0 {
36 {
37 crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
38 for it in &self.results {
39 it.encode(buf, version)?;
40 }
41 }
42 }
43 if flex {
44 let tagged = WriteTaggedFields::new();
45 tagged.write(buf, &self.unknown_tagged_fields);
46 }
47 Ok(())
48 }
49 fn encoded_len(&self, version: i16) -> usize {
50 let flex = is_flexible(version);
51 let mut n: usize = 0;
52 if version >= 0 {
53 n += {
54 let prefix =
55 crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
56 let body: usize = (self.results)
57 .iter()
58 .map(|it| it.encoded_len(version))
59 .sum();
60 prefix + body
61 };
62 }
63 if flex {
64 let known_pairs: Vec<(u32, usize)> = Vec::new();
65 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
66 }
67 n
68 }
69}
70impl Decode<'_> for ReadShareGroupStateResponse {
71 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
72 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
73 return Err(ProtocolError::UnsupportedVersion {
74 api_key: API_KEY,
75 version,
76 });
77 }
78 let flex = is_flexible(version);
79 let mut out = Self::default();
80 if version >= 0 {
81 out.results = {
82 let n = crate::primitives::array::get_array_len(buf, flex)?;
83 let mut v = Vec::with_capacity(n);
84 for _ in 0..n {
85 v.push(ReadStateResult::decode(buf, version)?);
86 }
87 v
88 };
89 }
90 if flex {
91 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
92 }
93 Ok(out)
94 }
95}
96#[cfg(test)]
97impl ReadShareGroupStateResponse {
98 #[must_use]
99 pub fn populated(version: i16) -> Self {
100 let mut m = Self::default();
101 if version >= 0 {
102 m.results = vec![ReadStateResult::populated(version)];
103 }
104 m
105 }
106}
107#[derive(Debug, Clone, PartialEq, Eq, Default)]
108pub struct ReadStateResult {
109 pub topic_id: crate::primitives::uuid::Uuid,
110 pub partitions: Vec<PartitionResult>,
111 pub unknown_tagged_fields: UnknownTaggedFields,
112}
113impl Encode for ReadStateResult {
114 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
115 let flex = version >= 0;
116 if version >= 0 {
117 crate::primitives::uuid::put_uuid(buf, self.topic_id);
118 }
119 if version >= 0 {
120 {
121 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
122 for it in &self.partitions {
123 it.encode(buf, version)?;
124 }
125 }
126 }
127 if flex {
128 let tagged = WriteTaggedFields::new();
129 tagged.write(buf, &self.unknown_tagged_fields);
130 }
131 Ok(())
132 }
133 fn encoded_len(&self, version: i16) -> usize {
134 let flex = version >= 0;
135 let mut n: usize = 0;
136 if version >= 0 {
137 n += 16;
138 }
139 if version >= 0 {
140 n += {
141 let prefix =
142 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
143 let body: usize = (self.partitions)
144 .iter()
145 .map(|it| it.encoded_len(version))
146 .sum();
147 prefix + body
148 };
149 }
150 if flex {
151 let known_pairs: Vec<(u32, usize)> = Vec::new();
152 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
153 }
154 n
155 }
156}
157impl Decode<'_> for ReadStateResult {
158 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
159 let flex = version >= 0;
160 let mut out = Self::default();
161 if version >= 0 {
162 out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
163 }
164 if version >= 0 {
165 out.partitions = {
166 let n = crate::primitives::array::get_array_len(buf, flex)?;
167 let mut v = Vec::with_capacity(n);
168 for _ in 0..n {
169 v.push(PartitionResult::decode(buf, version)?);
170 }
171 v
172 };
173 }
174 if flex {
175 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
176 }
177 Ok(out)
178 }
179}
180#[cfg(test)]
181impl ReadStateResult {
182 #[must_use]
183 pub fn populated(version: i16) -> Self {
184 let mut m = Self::default();
185 if version >= 0 {
186 m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
187 }
188 if version >= 0 {
189 m.partitions = vec![PartitionResult::populated(version)];
190 }
191 m
192 }
193}
194#[derive(Debug, Clone, PartialEq, Eq, Default)]
195pub struct PartitionResult {
196 pub partition: i32,
197 pub error_code: i16,
198 pub error_message: Option<String>,
199 pub state_epoch: i32,
200 pub start_offset: i64,
201 pub state_batches: Vec<StateBatch>,
202 pub unknown_tagged_fields: UnknownTaggedFields,
203}
204impl Encode for PartitionResult {
205 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
206 let flex = version >= 0;
207 if version >= 0 {
208 put_i32(buf, self.partition);
209 }
210 if version >= 0 {
211 put_i16(buf, self.error_code);
212 }
213 if version >= 0 {
214 if flex {
215 put_compact_nullable_string(buf, self.error_message.as_deref());
216 } else {
217 put_nullable_string(buf, self.error_message.as_deref());
218 }
219 }
220 if version >= 0 {
221 put_i32(buf, self.state_epoch);
222 }
223 if version >= 0 {
224 put_i64(buf, self.start_offset);
225 }
226 if version >= 0 {
227 {
228 crate::primitives::array::put_array_len(buf, (self.state_batches).len(), flex);
229 for it in &self.state_batches {
230 it.encode(buf, version)?;
231 }
232 }
233 }
234 if flex {
235 let tagged = WriteTaggedFields::new();
236 tagged.write(buf, &self.unknown_tagged_fields);
237 }
238 Ok(())
239 }
240 fn encoded_len(&self, version: i16) -> usize {
241 let flex = version >= 0;
242 let mut n: usize = 0;
243 if version >= 0 {
244 n += 4;
245 }
246 if version >= 0 {
247 n += 2;
248 }
249 if version >= 0 {
250 n += if flex {
251 compact_nullable_string_len(self.error_message.as_deref())
252 } else {
253 nullable_string_len(self.error_message.as_deref())
254 };
255 }
256 if version >= 0 {
257 n += 4;
258 }
259 if version >= 0 {
260 n += 8;
261 }
262 if version >= 0 {
263 n += {
264 let prefix = crate::primitives::array::array_len_prefix_len(
265 (self.state_batches).len(),
266 flex,
267 );
268 let body: usize = (self.state_batches)
269 .iter()
270 .map(|it| it.encoded_len(version))
271 .sum();
272 prefix + body
273 };
274 }
275 if flex {
276 let known_pairs: Vec<(u32, usize)> = Vec::new();
277 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
278 }
279 n
280 }
281}
282impl Decode<'_> for PartitionResult {
283 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
284 let flex = version >= 0;
285 let mut out = Self::default();
286 if version >= 0 {
287 out.partition = get_i32(buf)?;
288 }
289 if version >= 0 {
290 out.error_code = get_i16(buf)?;
291 }
292 if version >= 0 {
293 out.error_message = if flex {
294 get_compact_nullable_string_owned(buf)?
295 } else {
296 get_nullable_string_owned(buf)?
297 };
298 }
299 if version >= 0 {
300 out.state_epoch = get_i32(buf)?;
301 }
302 if version >= 0 {
303 out.start_offset = get_i64(buf)?;
304 }
305 if version >= 0 {
306 out.state_batches = {
307 let n = crate::primitives::array::get_array_len(buf, flex)?;
308 let mut v = Vec::with_capacity(n);
309 for _ in 0..n {
310 v.push(StateBatch::decode(buf, version)?);
311 }
312 v
313 };
314 }
315 if flex {
316 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
317 }
318 Ok(out)
319 }
320}
321#[cfg(test)]
322impl PartitionResult {
323 #[must_use]
324 pub fn populated(version: i16) -> Self {
325 let mut m = Self::default();
326 if version >= 0 {
327 m.partition = 1i32;
328 }
329 if version >= 0 {
330 m.error_code = 1i16;
331 }
332 if version >= 0 {
333 m.error_message = Some("x".to_string());
334 }
335 if version >= 0 {
336 m.state_epoch = 1i32;
337 }
338 if version >= 0 {
339 m.start_offset = 1i64;
340 }
341 if version >= 0 {
342 m.state_batches = vec![StateBatch::populated(version)];
343 }
344 m
345 }
346}
347#[derive(Debug, Clone, PartialEq, Eq, Default)]
348pub struct StateBatch {
349 pub first_offset: i64,
350 pub last_offset: i64,
351 pub delivery_state: i8,
352 pub delivery_count: i16,
353 pub unknown_tagged_fields: UnknownTaggedFields,
354}
355impl Encode for StateBatch {
356 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
357 let flex = version >= 0;
358 if version >= 0 {
359 put_i64(buf, self.first_offset);
360 }
361 if version >= 0 {
362 put_i64(buf, self.last_offset);
363 }
364 if version >= 0 {
365 put_i8(buf, self.delivery_state);
366 }
367 if version >= 0 {
368 put_i16(buf, self.delivery_count);
369 }
370 if flex {
371 let tagged = WriteTaggedFields::new();
372 tagged.write(buf, &self.unknown_tagged_fields);
373 }
374 Ok(())
375 }
376 fn encoded_len(&self, version: i16) -> usize {
377 let flex = version >= 0;
378 let mut n: usize = 0;
379 if version >= 0 {
380 n += 8;
381 }
382 if version >= 0 {
383 n += 8;
384 }
385 if version >= 0 {
386 n += 1;
387 }
388 if version >= 0 {
389 n += 2;
390 }
391 if flex {
392 let known_pairs: Vec<(u32, usize)> = Vec::new();
393 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
394 }
395 n
396 }
397}
398impl Decode<'_> for StateBatch {
399 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
400 let flex = version >= 0;
401 let mut out = Self::default();
402 if version >= 0 {
403 out.first_offset = get_i64(buf)?;
404 }
405 if version >= 0 {
406 out.last_offset = get_i64(buf)?;
407 }
408 if version >= 0 {
409 out.delivery_state = get_i8(buf)?;
410 }
411 if version >= 0 {
412 out.delivery_count = get_i16(buf)?;
413 }
414 if flex {
415 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
416 }
417 Ok(out)
418 }
419}
420#[cfg(test)]
421impl StateBatch {
422 #[must_use]
423 pub fn populated(version: i16) -> Self {
424 let mut m = Self::default();
425 if version >= 0 {
426 m.first_offset = 1i64;
427 }
428 if version >= 0 {
429 m.last_offset = 1i64;
430 }
431 if version >= 0 {
432 m.delivery_state = 1i8;
433 }
434 if version >= 0 {
435 m.delivery_count = 1i16;
436 }
437 m
438 }
439}
440#[must_use]
443#[allow(unused_comparisons)]
444pub fn default_json(version: i16) -> ::serde_json::Value {
445 let mut obj = ::serde_json::Map::new();
446 obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
447 ::serde_json::Value::Object(obj)
448}