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