crabka_protocol/opt/rustwide/workdir/generated/
ListGroupsRequest.owned.rs1use crate::primitives::string_bytes::{
4 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
5 string_len,
6};
7use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
8use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
9use bytes::{Buf, BufMut};
10
11pub const API_KEY: i16 = 16;
12pub const MIN_VERSION: i16 = 0;
13pub const MAX_VERSION: i16 = 5;
14pub const FLEXIBLE_MIN: i16 = 3;
15
16#[inline]
17fn is_flexible(version: i16) -> bool {
18 version >= FLEXIBLE_MIN
19}
20
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct ListGroupsRequest {
23 pub states_filter: Vec<String>,
24 pub types_filter: Vec<String>,
25 pub unknown_tagged_fields: UnknownTaggedFields,
26}
27impl Encode for ListGroupsRequest {
28 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
29 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
30 return Err(ProtocolError::UnsupportedVersion {
31 api_key: API_KEY,
32 version,
33 });
34 }
35 let flex = is_flexible(version);
36 if version >= 4 {
37 {
38 crate::primitives::array::put_array_len(buf, (self.states_filter).len(), flex);
39 for it in &self.states_filter {
40 if flex {
41 put_compact_string(buf, it);
42 } else {
43 put_string(buf, it);
44 }
45 }
46 }
47 }
48 if version >= 5 {
49 {
50 crate::primitives::array::put_array_len(buf, (self.types_filter).len(), flex);
51 for it in &self.types_filter {
52 if flex {
53 put_compact_string(buf, it);
54 } else {
55 put_string(buf, it);
56 }
57 }
58 }
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 >= 4 {
70 n += {
71 let prefix = crate::primitives::array::array_len_prefix_len(
72 (self.states_filter).len(),
73 flex,
74 );
75 let body: usize = (self.states_filter)
76 .iter()
77 .map(|it| {
78 if flex {
79 compact_string_len(it)
80 } else {
81 string_len(it)
82 }
83 })
84 .sum();
85 prefix + body
86 };
87 }
88 if version >= 5 {
89 n += {
90 let prefix =
91 crate::primitives::array::array_len_prefix_len((self.types_filter).len(), flex);
92 let body: usize = (self.types_filter)
93 .iter()
94 .map(|it| {
95 if flex {
96 compact_string_len(it)
97 } else {
98 string_len(it)
99 }
100 })
101 .sum();
102 prefix + body
103 };
104 }
105 if flex {
106 let known_pairs: Vec<(u32, usize)> = Vec::new();
107 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
108 }
109 n
110 }
111}
112impl Decode<'_> for ListGroupsRequest {
113 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
114 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
115 return Err(ProtocolError::UnsupportedVersion {
116 api_key: API_KEY,
117 version,
118 });
119 }
120 let flex = is_flexible(version);
121 let mut out = Self::default();
122 if version >= 4 {
123 out.states_filter = {
124 let n = crate::primitives::array::get_array_len(buf, flex)?;
125 let mut v = Vec::with_capacity(n);
126 for _ in 0..n {
127 v.push(if flex {
128 get_compact_string_owned(buf)?
129 } else {
130 get_string_owned(buf)?
131 });
132 }
133 v
134 };
135 }
136 if version >= 5 {
137 out.types_filter = {
138 let n = crate::primitives::array::get_array_len(buf, flex)?;
139 let mut v = Vec::with_capacity(n);
140 for _ in 0..n {
141 v.push(if flex {
142 get_compact_string_owned(buf)?
143 } else {
144 get_string_owned(buf)?
145 });
146 }
147 v
148 };
149 }
150 if flex {
151 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
152 }
153 Ok(out)
154 }
155}
156#[cfg(test)]
157impl ListGroupsRequest {
158 #[must_use]
159 pub fn populated(version: i16) -> Self {
160 let mut m = Self::default();
161 if version >= 4 {
162 m.states_filter = vec!["x".to_string()];
163 }
164 if version >= 5 {
165 m.types_filter = vec!["x".to_string()];
166 }
167 m
168 }
169}
170
171#[must_use]
174#[allow(unused_comparisons)]
175pub fn default_json(version: i16) -> ::serde_json::Value {
176 let mut obj = ::serde_json::Map::new();
177 if version >= 4 {
178 obj.insert(
179 "statesFilter".to_string(),
180 ::serde_json::Value::Array(vec![]),
181 );
182 }
183 if version >= 5 {
184 obj.insert(
185 "typesFilter".to_string(),
186 ::serde_json::Value::Array(vec![]),
187 );
188 }
189 ::serde_json::Value::Object(obj)
190}
191
192impl crate::ProtocolRequest for ListGroupsRequest {
193 const API_KEY: i16 = API_KEY;
194 const MIN_VERSION: i16 = MIN_VERSION;
195 const MAX_VERSION: i16 = MAX_VERSION;
196 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
197 type Response = super::list_groups_response::ListGroupsResponse;
198}