crabka_protocol/opt/rustwide/workdir/generated/
DescribeClientQuotasRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, get_i8, put_bool, put_i8};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8 get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
10};
11use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
12use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
13
14pub const API_KEY: i16 = 48;
15pub const MIN_VERSION: i16 = 0;
16pub const MAX_VERSION: i16 = 1;
17pub const FLEXIBLE_MIN: i16 = 1;
18
19#[inline]
20fn is_flexible(version: i16) -> bool {
21 version >= FLEXIBLE_MIN
22}
23
24#[derive(Debug, Clone, PartialEq, Eq, Default)]
25pub struct DescribeClientQuotasRequest {
26 pub components: Vec<ComponentData>,
27 pub strict: bool,
28 pub unknown_tagged_fields: UnknownTaggedFields,
29}
30impl Encode for DescribeClientQuotasRequest {
31 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
32 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
33 return Err(ProtocolError::UnsupportedVersion {
34 api_key: API_KEY,
35 version,
36 });
37 }
38 let flex = is_flexible(version);
39 if version >= 0 {
40 {
41 crate::primitives::array::put_array_len(buf, (self.components).len(), flex);
42 for it in &self.components {
43 it.encode(buf, version)?;
44 }
45 }
46 }
47 if version >= 0 {
48 put_bool(buf, self.strict);
49 }
50 if flex {
51 let tagged = WriteTaggedFields::new();
52 tagged.write(buf, &self.unknown_tagged_fields);
53 }
54 Ok(())
55 }
56 fn encoded_len(&self, version: i16) -> usize {
57 let flex = is_flexible(version);
58 let mut n: usize = 0;
59 if version >= 0 {
60 n += {
61 let prefix =
62 crate::primitives::array::array_len_prefix_len((self.components).len(), flex);
63 let body: usize = (self.components)
64 .iter()
65 .map(|it| it.encoded_len(version))
66 .sum();
67 prefix + body
68 };
69 }
70 if version >= 0 {
71 n += 1;
72 }
73 if flex {
74 let known_pairs: Vec<(u32, usize)> = Vec::new();
75 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
76 }
77 n
78 }
79}
80impl Decode<'_> for DescribeClientQuotasRequest {
81 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
82 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
83 return Err(ProtocolError::UnsupportedVersion {
84 api_key: API_KEY,
85 version,
86 });
87 }
88 let flex = is_flexible(version);
89 let mut out = Self::default();
90 if version >= 0 {
91 out.components = {
92 let n = crate::primitives::array::get_array_len(buf, flex)?;
93 let mut v = Vec::with_capacity(n);
94 for _ in 0..n {
95 v.push(ComponentData::decode(buf, version)?);
96 }
97 v
98 };
99 }
100 if version >= 0 {
101 out.strict = get_bool(buf)?;
102 }
103 if flex {
104 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
105 }
106 Ok(out)
107 }
108}
109#[cfg(test)]
110impl DescribeClientQuotasRequest {
111 #[must_use]
112 pub fn populated(version: i16) -> Self {
113 let mut m = Self::default();
114 if version >= 0 {
115 m.components = vec![ComponentData::populated(version)];
116 }
117 if version >= 0 {
118 m.strict = true;
119 }
120 m
121 }
122}
123#[derive(Debug, Clone, PartialEq, Eq, Default)]
124pub struct ComponentData {
125 pub entity_type: String,
126 pub match_type: i8,
127 pub match_: Option<String>,
128 pub unknown_tagged_fields: UnknownTaggedFields,
129}
130impl Encode for ComponentData {
131 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
132 let flex = version >= 1;
133 if version >= 0 {
134 if flex {
135 put_compact_string(buf, &self.entity_type);
136 } else {
137 put_string(buf, &self.entity_type);
138 }
139 }
140 if version >= 0 {
141 put_i8(buf, self.match_type);
142 }
143 if version >= 0 {
144 if flex {
145 put_compact_nullable_string(buf, self.match_.as_deref());
146 } else {
147 put_nullable_string(buf, self.match_.as_deref());
148 }
149 }
150 if flex {
151 let tagged = WriteTaggedFields::new();
152 tagged.write(buf, &self.unknown_tagged_fields);
153 }
154 Ok(())
155 }
156 fn encoded_len(&self, version: i16) -> usize {
157 let flex = version >= 1;
158 let mut n: usize = 0;
159 if version >= 0 {
160 n += if flex {
161 compact_string_len(&self.entity_type)
162 } else {
163 string_len(&self.entity_type)
164 };
165 }
166 if version >= 0 {
167 n += 1;
168 }
169 if version >= 0 {
170 n += if flex {
171 compact_nullable_string_len(self.match_.as_deref())
172 } else {
173 nullable_string_len(self.match_.as_deref())
174 };
175 }
176 if flex {
177 let known_pairs: Vec<(u32, usize)> = Vec::new();
178 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
179 }
180 n
181 }
182}
183impl Decode<'_> for ComponentData {
184 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
185 let flex = version >= 1;
186 let mut out = Self::default();
187 if version >= 0 {
188 out.entity_type = if flex {
189 get_compact_string_owned(buf)?
190 } else {
191 get_string_owned(buf)?
192 };
193 }
194 if version >= 0 {
195 out.match_type = get_i8(buf)?;
196 }
197 if version >= 0 {
198 out.match_ = if flex {
199 get_compact_nullable_string_owned(buf)?
200 } else {
201 get_nullable_string_owned(buf)?
202 };
203 }
204 if flex {
205 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
206 }
207 Ok(out)
208 }
209}
210#[cfg(test)]
211impl ComponentData {
212 #[must_use]
213 pub fn populated(version: i16) -> Self {
214 let mut m = Self::default();
215 if version >= 0 {
216 m.entity_type = "x".to_string();
217 }
218 if version >= 0 {
219 m.match_type = 1i8;
220 }
221 if version >= 0 {
222 m.match_ = Some("x".to_string());
223 }
224 m
225 }
226}
227
228#[must_use]
231#[allow(unused_comparisons)]
232pub fn default_json(version: i16) -> ::serde_json::Value {
233 let mut obj = ::serde_json::Map::new();
234 obj.insert("components".to_string(), ::serde_json::Value::Array(vec![]));
235 obj.insert("strict".to_string(), ::serde_json::Value::Bool(false));
236 ::serde_json::Value::Object(obj)
237}
238
239impl crate::ProtocolRequest for DescribeClientQuotasRequest {
240 const API_KEY: i16 = API_KEY;
241 const MIN_VERSION: i16 = MIN_VERSION;
242 const MAX_VERSION: i16 = MAX_VERSION;
243 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
244 type Response = super::describe_client_quotas_response::DescribeClientQuotasResponse;
245}