krabka_protocol/opt/rustwide/workdir/generated/
StreamsGroupDescribeRequest.owned.rs1use 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 = 89;
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 StreamsGroupDescribeRequest {
29 pub group_ids: Vec<String>,
30 pub include_authorized_operations: bool,
31 pub include_topology_description: bool,
32 pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Encode for StreamsGroupDescribeRequest {
35 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
36 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
37 return Err(ProtocolError::UnsupportedVersion {
38 api_key: API_KEY,
39 version,
40 });
41 }
42 let flex = is_flexible(version);
43 if version >= 0 {
44 {
45 put_array_len(buf, (self.group_ids).len(), flex)?;
46 for it in &self.group_ids {
47 if flex {
48 put_compact_string(buf, it)?;
49 } else {
50 put_string(buf, it)?;
51 }
52 }
53 }
54 }
55 if version >= 0 {
56 put_bool(buf, self.include_authorized_operations);
57 }
58 if version >= 1 {
59 put_bool(buf, self.include_topology_description);
60 }
61 if flex {
62 let tagged = WriteTaggedFields::new();
63 tagged.write(buf, &self.unknown_tagged_fields)?;
64 }
65 Ok(())
66 }
67 fn encoded_len(&self, version: i16) -> usize {
68 let flex = is_flexible(version);
69 let mut n: usize = 0;
70 if version >= 0 {
71 n += {
72 let prefix = 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 = 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_owned()];
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#[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_owned(), ::serde_json::Value::Array(vec![]));
159 obj.insert(
160 "includeAuthorizedOperations".to_owned(),
161 ::serde_json::Value::Bool(false),
162 );
163 if version >= 1 {
164 obj.insert(
165 "includeTopologyDescription".to_owned(),
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}