krabka_protocol/opt/rustwide/workdir/generated/
DescribeGroupsRequest.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 = 15;
18pub const MIN_VERSION: i16 = 0;
19pub const MAX_VERSION: i16 = 6;
20pub const LATEST_STABLE_VERSION: i16 = 6;
21pub const FLEXIBLE_MIN: i16 = 5;
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 DescribeGroupsRequest {
29 pub groups: Vec<String>,
30 pub include_authorized_operations: bool,
31 pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl Encode for DescribeGroupsRequest {
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.groups).len(), flex)?;
45 for it in &self.groups {
46 if flex {
47 put_compact_string(buf, it)?;
48 } else {
49 put_string(buf, it)?;
50 }
51 }
52 }
53 }
54 if version >= 3 {
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.groups).len(), flex);
69 let body: usize = (self.groups)
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 >= 3 {
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 DescribeGroupsRequest {
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.groups = {
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 >= 3 {
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 DescribeGroupsRequest {
127 #[must_use]
128 pub fn populated(version: i16) -> Self {
129 let mut m = Self::default();
130 if version >= 0 {
131 m.groups = vec!["x".to_owned()];
132 }
133 if version >= 3 {
134 m.include_authorized_operations = true;
135 }
136 m
137 }
138}
139#[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("groups".to_owned(), ::serde_json::Value::Array(vec![]));
146 if version >= 3 {
147 obj.insert(
148 "includeAuthorizedOperations".to_owned(),
149 ::serde_json::Value::Bool(false),
150 );
151 }
152 ::serde_json::Value::Object(obj)
153}
154impl crate::ProtocolRequest for DescribeGroupsRequest {
155 const API_KEY: i16 = API_KEY;
156 const MIN_VERSION: i16 = MIN_VERSION;
157 const MAX_VERSION: i16 = MAX_VERSION;
158 const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
159 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
160 type Response = super::describe_groups_response::DescribeGroupsResponse;
161}