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