crabka_protocol/opt/rustwide/workdir/generated/
DescribeGroupsRequest.owned.rs1use 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 = 15;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 6;
16pub const FLEXIBLE_MIN: i16 = 5;
17
18#[inline]
19fn is_flexible(version: i16) -> bool {
20 version >= FLEXIBLE_MIN
21}
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct DescribeGroupsRequest {
25 pub groups: Vec<String>,
26 pub include_authorized_operations: bool,
27 pub unknown_tagged_fields: UnknownTaggedFields,
28}
29impl Encode for DescribeGroupsRequest {
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.groups).len(), flex);
41 for it in &self.groups {
42 if flex {
43 put_compact_string(buf, it);
44 } else {
45 put_string(buf, it);
46 }
47 }
48 }
49 }
50 if version >= 3 {
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.groups).len(), flex);
66 let body: usize = (self.groups)
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 >= 3 {
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 DescribeGroupsRequest {
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.groups = {
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 >= 3 {
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 DescribeGroupsRequest {
124 #[must_use]
125 pub fn populated(version: i16) -> Self {
126 let mut m = Self::default();
127 if version >= 0 {
128 m.groups = vec!["x".to_string()];
129 }
130 if version >= 3 {
131 m.include_authorized_operations = true;
132 }
133 m
134 }
135}
136
137#[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("groups".to_string(), ::serde_json::Value::Array(vec![]));
144 if version >= 3 {
145 obj.insert(
146 "includeAuthorizedOperations".to_string(),
147 ::serde_json::Value::Bool(false),
148 );
149 }
150 ::serde_json::Value::Object(obj)
151}
152
153impl crate::ProtocolRequest for DescribeGroupsRequest {
154 const API_KEY: i16 = API_KEY;
155 const MIN_VERSION: i16 = MIN_VERSION;
156 const MAX_VERSION: i16 = MAX_VERSION;
157 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
158 type Response = super::describe_groups_response::DescribeGroupsResponse;
159}