Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
ConsumerGroupDescribeRequest.owned.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use 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_bool, put_bool},
10        string_bytes::{
11            compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
12            put_string, string_len,
13        },
14    },
15    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
16};
17pub const API_KEY: i16 = 69;
18pub const MIN_VERSION: i16 = 0;
19pub const MAX_VERSION: i16 = 1;
20pub const LATEST_STABLE_VERSION: i16 = 1;
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 ConsumerGroupDescribeRequest {
29    pub group_ids: Vec<String>,
30    pub include_authorized_operations: bool,
31    pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl Encode for ConsumerGroupDescribeRequest {
34    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
35        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
36            return Err(ProtocolError::UnsupportedVersion {
37                api_key: API_KEY,
38                version,
39            });
40        }
41        let flex = is_flexible(version);
42        if version >= 0 {
43            {
44                put_array_len(buf, (self.group_ids).len(), flex)?;
45                for it in &self.group_ids {
46                    if flex {
47                        put_compact_string(buf, it)?;
48                    } else {
49                        put_string(buf, it)?;
50                    }
51                }
52            }
53        }
54        if version >= 0 {
55            put_bool(buf, self.include_authorized_operations);
56        }
57        if flex {
58            let tagged = WriteTaggedFields::new();
59            tagged.write(buf, &self.unknown_tagged_fields)?;
60        }
61        Ok(())
62    }
63    fn encoded_len(&self, version: i16) -> usize {
64        let flex = is_flexible(version);
65        let mut n: usize = 0;
66        if version >= 0 {
67            n += {
68                let prefix = array_len_prefix_len((self.group_ids).len(), flex);
69                let body: usize = (self.group_ids)
70                    .iter()
71                    .map(|it| {
72                        if flex {
73                            compact_string_len(it)
74                        } else {
75                            string_len(it)
76                        }
77                    })
78                    .sum();
79                prefix + body
80            };
81        }
82        if version >= 0 {
83            n += 1;
84        }
85        if flex {
86            let known_pairs: Vec<(u32, usize)> = Vec::new();
87            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
88        }
89        n
90    }
91}
92impl Decode<'_> for ConsumerGroupDescribeRequest {
93    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
94        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
95            return Err(ProtocolError::UnsupportedVersion {
96                api_key: API_KEY,
97                version,
98            });
99        }
100        let flex = is_flexible(version);
101        let mut out = Self::default();
102        if version >= 0 {
103            out.group_ids = {
104                let n = get_array_len(buf, flex)?;
105                let mut v = Vec::with_capacity(n);
106                for _ in 0..n {
107                    v.push(if flex {
108                        get_compact_string_owned(buf)?
109                    } else {
110                        get_string_owned(buf)?
111                    });
112                }
113                v
114            };
115        }
116        if version >= 0 {
117            out.include_authorized_operations = get_bool(buf)?;
118        }
119        if flex {
120            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
121        }
122        Ok(out)
123    }
124}
125#[cfg(test)]
126impl ConsumerGroupDescribeRequest {
127    #[must_use]
128    pub fn populated(version: i16) -> Self {
129        let mut m = Self::default();
130        if version >= 0 {
131            m.group_ids = vec!["x".to_owned()];
132        }
133        if version >= 0 {
134            m.include_authorized_operations = true;
135        }
136        m
137    }
138}
139/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
140/// Only includes fields valid for the given version.
141#[must_use]
142#[allow(unused_comparisons)]
143pub fn default_json(_version: i16) -> ::serde_json::Value {
144    let mut obj = ::serde_json::Map::new();
145    obj.insert("groupIds".to_owned(), ::serde_json::Value::Array(vec![]));
146    obj.insert(
147        "includeAuthorizedOperations".to_owned(),
148        ::serde_json::Value::Bool(false),
149    );
150    ::serde_json::Value::Object(obj)
151}
152impl crate::ProtocolRequest for ConsumerGroupDescribeRequest {
153    const API_KEY: i16 = API_KEY;
154    const MIN_VERSION: i16 = MIN_VERSION;
155    const MAX_VERSION: i16 = MAX_VERSION;
156    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
157    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
158    type Response = super::consumer_group_describe_response::ConsumerGroupDescribeResponse;
159}