Skip to main content

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

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