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