Skip to main content

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