Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ShareGroupDescribeResponse.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use 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 = 77;
13pub const MIN_VERSION: i16 = 1;
14pub const MAX_VERSION: i16 = 1;
15pub const FLEXIBLE_MIN: i16 = 0;
16#[inline]
17fn is_flexible(version: i16) -> bool {
18    version >= FLEXIBLE_MIN
19}
20#[derive(Debug, Clone, PartialEq, Eq, Default)]
21pub struct ShareGroupDescribeResponse {
22    pub throttle_time_ms: i32,
23    pub groups: Vec<DescribedGroup>,
24    pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl Encode for ShareGroupDescribeResponse {
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            put_i32(buf, self.throttle_time_ms);
37        }
38        if version >= 0 {
39            {
40                crate::primitives::array::put_array_len(buf, (self.groups).len(), flex);
41                for it in &self.groups {
42                    it.encode(buf, version)?;
43                }
44            }
45        }
46        if flex {
47            let tagged = WriteTaggedFields::new();
48            tagged.write(buf, &self.unknown_tagged_fields);
49        }
50        Ok(())
51    }
52    fn encoded_len(&self, version: i16) -> usize {
53        let flex = is_flexible(version);
54        let mut n: usize = 0;
55        if version >= 0 {
56            n += 4;
57        }
58        if version >= 0 {
59            n += {
60                let prefix =
61                    crate::primitives::array::array_len_prefix_len((self.groups).len(), flex);
62                let body: usize = (self.groups).iter().map(|it| it.encoded_len(version)).sum();
63                prefix + body
64            };
65        }
66        if flex {
67            let known_pairs: Vec<(u32, usize)> = Vec::new();
68            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
69        }
70        n
71    }
72}
73impl Decode<'_> for ShareGroupDescribeResponse {
74    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
75        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
76            return Err(ProtocolError::UnsupportedVersion {
77                api_key: API_KEY,
78                version,
79            });
80        }
81        let flex = is_flexible(version);
82        let mut out = Self::default();
83        if version >= 0 {
84            out.throttle_time_ms = get_i32(buf)?;
85        }
86        if version >= 0 {
87            out.groups = {
88                let n = crate::primitives::array::get_array_len(buf, flex)?;
89                let mut v = Vec::with_capacity(n);
90                for _ in 0..n {
91                    v.push(DescribedGroup::decode(buf, version)?);
92                }
93                v
94            };
95        }
96        if flex {
97            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
98        }
99        Ok(out)
100    }
101}
102#[cfg(test)]
103impl ShareGroupDescribeResponse {
104    #[must_use]
105    pub fn populated(version: i16) -> Self {
106        let mut m = Self::default();
107        if version >= 0 {
108            m.throttle_time_ms = 1i32;
109        }
110        if version >= 0 {
111            m.groups = vec![DescribedGroup::populated(version)];
112        }
113        m
114    }
115}
116#[derive(Debug, Clone, PartialEq, Eq)]
117pub struct DescribedGroup {
118    pub error_code: i16,
119    pub error_message: Option<String>,
120    pub group_id: String,
121    pub group_state: String,
122    pub group_epoch: i32,
123    pub assignment_epoch: i32,
124    pub assignor_name: String,
125    pub members: Vec<Member>,
126    pub authorized_operations: i32,
127    pub unknown_tagged_fields: UnknownTaggedFields,
128}
129impl Default for DescribedGroup {
130    fn default() -> Self {
131        Self {
132            error_code: 0i16,
133            error_message: None,
134            group_id: String::new(),
135            group_state: String::new(),
136            group_epoch: 0i32,
137            assignment_epoch: 0i32,
138            assignor_name: String::new(),
139            members: Vec::new(),
140            authorized_operations: -2_147_483_648i32,
141            unknown_tagged_fields: Default::default(),
142        }
143    }
144}
145impl Encode for DescribedGroup {
146    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
147        let flex = version >= 0;
148        if version >= 0 {
149            put_i16(buf, self.error_code);
150        }
151        if version >= 0 {
152            if flex {
153                put_compact_nullable_string(buf, self.error_message.as_deref());
154            } else {
155                put_nullable_string(buf, self.error_message.as_deref());
156            }
157        }
158        if version >= 0 {
159            if flex {
160                put_compact_string(buf, &self.group_id);
161            } else {
162                put_string(buf, &self.group_id);
163            }
164        }
165        if version >= 0 {
166            if flex {
167                put_compact_string(buf, &self.group_state);
168            } else {
169                put_string(buf, &self.group_state);
170            }
171        }
172        if version >= 0 {
173            put_i32(buf, self.group_epoch);
174        }
175        if version >= 0 {
176            put_i32(buf, self.assignment_epoch);
177        }
178        if version >= 0 {
179            if flex {
180                put_compact_string(buf, &self.assignor_name);
181            } else {
182                put_string(buf, &self.assignor_name);
183            }
184        }
185        if version >= 0 {
186            {
187                crate::primitives::array::put_array_len(buf, (self.members).len(), flex);
188                for it in &self.members {
189                    it.encode(buf, version)?;
190                }
191            }
192        }
193        if version >= 0 {
194            put_i32(buf, self.authorized_operations);
195        }
196        if flex {
197            let tagged = WriteTaggedFields::new();
198            tagged.write(buf, &self.unknown_tagged_fields);
199        }
200        Ok(())
201    }
202    fn encoded_len(&self, version: i16) -> usize {
203        let flex = version >= 0;
204        let mut n: usize = 0;
205        if version >= 0 {
206            n += 2;
207        }
208        if version >= 0 {
209            n += if flex {
210                compact_nullable_string_len(self.error_message.as_deref())
211            } else {
212                nullable_string_len(self.error_message.as_deref())
213            };
214        }
215        if version >= 0 {
216            n += if flex {
217                compact_string_len(&self.group_id)
218            } else {
219                string_len(&self.group_id)
220            };
221        }
222        if version >= 0 {
223            n += if flex {
224                compact_string_len(&self.group_state)
225            } else {
226                string_len(&self.group_state)
227            };
228        }
229        if version >= 0 {
230            n += 4;
231        }
232        if version >= 0 {
233            n += 4;
234        }
235        if version >= 0 {
236            n += if flex {
237                compact_string_len(&self.assignor_name)
238            } else {
239                string_len(&self.assignor_name)
240            };
241        }
242        if version >= 0 {
243            n += {
244                let prefix =
245                    crate::primitives::array::array_len_prefix_len((self.members).len(), flex);
246                let body: usize = (self.members)
247                    .iter()
248                    .map(|it| it.encoded_len(version))
249                    .sum();
250                prefix + body
251            };
252        }
253        if version >= 0 {
254            n += 4;
255        }
256        if flex {
257            let known_pairs: Vec<(u32, usize)> = Vec::new();
258            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
259        }
260        n
261    }
262}
263impl Decode<'_> for DescribedGroup {
264    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
265        let flex = version >= 0;
266        let mut out = Self::default();
267        if version >= 0 {
268            out.error_code = get_i16(buf)?;
269        }
270        if version >= 0 {
271            out.error_message = if flex {
272                get_compact_nullable_string_owned(buf)?
273            } else {
274                get_nullable_string_owned(buf)?
275            };
276        }
277        if version >= 0 {
278            out.group_id = if flex {
279                get_compact_string_owned(buf)?
280            } else {
281                get_string_owned(buf)?
282            };
283        }
284        if version >= 0 {
285            out.group_state = if flex {
286                get_compact_string_owned(buf)?
287            } else {
288                get_string_owned(buf)?
289            };
290        }
291        if version >= 0 {
292            out.group_epoch = get_i32(buf)?;
293        }
294        if version >= 0 {
295            out.assignment_epoch = get_i32(buf)?;
296        }
297        if version >= 0 {
298            out.assignor_name = if flex {
299                get_compact_string_owned(buf)?
300            } else {
301                get_string_owned(buf)?
302            };
303        }
304        if version >= 0 {
305            out.members = {
306                let n = crate::primitives::array::get_array_len(buf, flex)?;
307                let mut v = Vec::with_capacity(n);
308                for _ in 0..n {
309                    v.push(Member::decode(buf, version)?);
310                }
311                v
312            };
313        }
314        if version >= 0 {
315            out.authorized_operations = get_i32(buf)?;
316        }
317        if flex {
318            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
319        }
320        Ok(out)
321    }
322}
323#[cfg(test)]
324impl DescribedGroup {
325    #[must_use]
326    pub fn populated(version: i16) -> Self {
327        let mut m = Self::default();
328        if version >= 0 {
329            m.error_code = 1i16;
330        }
331        if version >= 0 {
332            m.error_message = Some("x".to_string());
333        }
334        if version >= 0 {
335            m.group_id = "x".to_string();
336        }
337        if version >= 0 {
338            m.group_state = "x".to_string();
339        }
340        if version >= 0 {
341            m.group_epoch = 1i32;
342        }
343        if version >= 0 {
344            m.assignment_epoch = 1i32;
345        }
346        if version >= 0 {
347            m.assignor_name = "x".to_string();
348        }
349        if version >= 0 {
350            m.members = vec![Member::populated(version)];
351        }
352        if version >= 0 {
353            m.authorized_operations = 1i32;
354        }
355        m
356    }
357}
358#[derive(Debug, Clone, PartialEq, Eq, Default)]
359pub struct Member {
360    pub member_id: String,
361    pub rack_id: Option<String>,
362    pub member_epoch: i32,
363    pub client_id: String,
364    pub client_host: String,
365    pub subscribed_topic_names: Vec<String>,
366    pub assignment: super::common::share_group_describe_response::assignment::Assignment,
367    pub unknown_tagged_fields: UnknownTaggedFields,
368}
369impl Encode for Member {
370    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
371        let flex = version >= 0;
372        if version >= 0 {
373            if flex {
374                put_compact_string(buf, &self.member_id);
375            } else {
376                put_string(buf, &self.member_id);
377            }
378        }
379        if version >= 0 {
380            if flex {
381                put_compact_nullable_string(buf, self.rack_id.as_deref());
382            } else {
383                put_nullable_string(buf, self.rack_id.as_deref());
384            }
385        }
386        if version >= 0 {
387            put_i32(buf, self.member_epoch);
388        }
389        if version >= 0 {
390            if flex {
391                put_compact_string(buf, &self.client_id);
392            } else {
393                put_string(buf, &self.client_id);
394            }
395        }
396        if version >= 0 {
397            if flex {
398                put_compact_string(buf, &self.client_host);
399            } else {
400                put_string(buf, &self.client_host);
401            }
402        }
403        if version >= 0 {
404            {
405                crate::primitives::array::put_array_len(
406                    buf,
407                    (self.subscribed_topic_names).len(),
408                    flex,
409                );
410                for it in &self.subscribed_topic_names {
411                    if flex {
412                        put_compact_string(buf, it);
413                    } else {
414                        put_string(buf, it);
415                    }
416                }
417            }
418        }
419        if version >= 0 {
420            self.assignment.encode(buf, version)?;
421        }
422        if flex {
423            let tagged = WriteTaggedFields::new();
424            tagged.write(buf, &self.unknown_tagged_fields);
425        }
426        Ok(())
427    }
428    fn encoded_len(&self, version: i16) -> usize {
429        let flex = version >= 0;
430        let mut n: usize = 0;
431        if version >= 0 {
432            n += if flex {
433                compact_string_len(&self.member_id)
434            } else {
435                string_len(&self.member_id)
436            };
437        }
438        if version >= 0 {
439            n += if flex {
440                compact_nullable_string_len(self.rack_id.as_deref())
441            } else {
442                nullable_string_len(self.rack_id.as_deref())
443            };
444        }
445        if version >= 0 {
446            n += 4;
447        }
448        if version >= 0 {
449            n += if flex {
450                compact_string_len(&self.client_id)
451            } else {
452                string_len(&self.client_id)
453            };
454        }
455        if version >= 0 {
456            n += if flex {
457                compact_string_len(&self.client_host)
458            } else {
459                string_len(&self.client_host)
460            };
461        }
462        if version >= 0 {
463            n += {
464                let prefix = crate::primitives::array::array_len_prefix_len(
465                    (self.subscribed_topic_names).len(),
466                    flex,
467                );
468                let body: usize = (self.subscribed_topic_names)
469                    .iter()
470                    .map(|it| {
471                        if flex {
472                            compact_string_len(it)
473                        } else {
474                            string_len(it)
475                        }
476                    })
477                    .sum();
478                prefix + body
479            };
480        }
481        if version >= 0 {
482            n += self.assignment.encoded_len(version);
483        }
484        if flex {
485            let known_pairs: Vec<(u32, usize)> = Vec::new();
486            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
487        }
488        n
489    }
490}
491impl Decode<'_> for Member {
492    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
493        let flex = version >= 0;
494        let mut out = Self::default();
495        if version >= 0 {
496            out.member_id = if flex {
497                get_compact_string_owned(buf)?
498            } else {
499                get_string_owned(buf)?
500            };
501        }
502        if version >= 0 {
503            out.rack_id = if flex {
504                get_compact_nullable_string_owned(buf)?
505            } else {
506                get_nullable_string_owned(buf)?
507            };
508        }
509        if version >= 0 {
510            out.member_epoch = get_i32(buf)?;
511        }
512        if version >= 0 {
513            out.client_id = if flex {
514                get_compact_string_owned(buf)?
515            } else {
516                get_string_owned(buf)?
517            };
518        }
519        if version >= 0 {
520            out.client_host = if flex {
521                get_compact_string_owned(buf)?
522            } else {
523                get_string_owned(buf)?
524            };
525        }
526        if version >= 0 {
527            out.subscribed_topic_names = {
528                let n = crate::primitives::array::get_array_len(buf, flex)?;
529                let mut v = Vec::with_capacity(n);
530                for _ in 0..n {
531                    v.push(if flex {
532                        get_compact_string_owned(buf)?
533                    } else {
534                        get_string_owned(buf)?
535                    });
536                }
537                v
538            };
539        }
540        if version >= 0 {
541            out.assignment =
542                super::common::share_group_describe_response::assignment::Assignment::decode(
543                    buf, version,
544                )?;
545        }
546        if flex {
547            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
548        }
549        Ok(out)
550    }
551}
552#[cfg(test)]
553impl Member {
554    #[must_use]
555    pub fn populated(version: i16) -> Self {
556        let mut m = Self::default();
557        if version >= 0 {
558            m.member_id = "x".to_string();
559        }
560        if version >= 0 {
561            m.rack_id = Some("x".to_string());
562        }
563        if version >= 0 {
564            m.member_epoch = 1i32;
565        }
566        if version >= 0 {
567            m.client_id = "x".to_string();
568        }
569        if version >= 0 {
570            m.client_host = "x".to_string();
571        }
572        if version >= 0 {
573            m.subscribed_topic_names = vec!["x".to_string()];
574        }
575        if version >= 0 {
576            m.assignment =
577                super::common::share_group_describe_response::assignment::Assignment::populated(
578                    version,
579                );
580        }
581        m
582    }
583}
584/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
585/// Only includes fields valid for the given version.
586#[must_use]
587#[allow(unused_comparisons)]
588pub fn default_json(version: i16) -> ::serde_json::Value {
589    let mut obj = ::serde_json::Map::new();
590    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
591    obj.insert("groups".to_string(), ::serde_json::Value::Array(vec![]));
592    ::serde_json::Value::Object(obj)
593}