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