crabka_protocol/opt/rustwide/workdir/generated/
DescribeClientQuotasResponse.borrowed.rs1use bytes::BufMut;
4
5use crate::primitives::fixed::{get_f64, get_i16, get_i32, put_f64, put_i16, put_i32};
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,
9 string_len,
10};
11use crate::primitives::string_bytes_borrowed::{
12 get_compact_nullable_string_borrowed, get_compact_string_borrowed,
13 get_nullable_string_borrowed, get_string_borrowed,
14};
15use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
16use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
17
18pub const API_KEY: i16 = 48;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 1;
21pub const FLEXIBLE_MIN: i16 = 1;
22
23#[inline]
24fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
25
26#[derive(Debug, Clone, PartialEq)]
27pub struct DescribeClientQuotasResponse<'a> {
28 pub throttle_time_ms: i32,
29 pub error_code: i16,
30 pub error_message: Option<&'a str>,
31 pub entries: Option<Vec<EntryData<'a>>>,
32 pub unknown_tagged_fields: UnknownTaggedFields,
33}
34
35impl<'a> Default for DescribeClientQuotasResponse<'a> {
36 fn default() -> Self {
37 Self {
38 throttle_time_ms: 0i32,
39 error_code: 0i16,
40 error_message: None,
41 entries: None,
42 unknown_tagged_fields: Default::default(),
43 }
44 }
45}
46
47impl<'a> DescribeClientQuotasResponse<'a> {
48 pub fn to_owned(&self) -> crate::owned::describe_client_quotas_response::DescribeClientQuotasResponse {
49 crate::owned::describe_client_quotas_response::DescribeClientQuotasResponse {
50 throttle_time_ms: (self.throttle_time_ms),
51 error_code: (self.error_code),
52 error_message: (self.error_message).map(|s| s.to_string()),
53 entries: (self.entries).as_ref().map(|v| v.iter().map(|it| it.to_owned()).collect()),
54 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
55 }
56 }
57}
58
59impl<'a> Encode for DescribeClientQuotasResponse<'a> {
60 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
61 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
62 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
63 }
64 let flex = is_flexible(version);
65 if version >= 0 { put_i32(buf, self.throttle_time_ms) }
66 if version >= 0 { put_i16(buf, self.error_code) }
67 if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message) } else { put_nullable_string(buf, self.error_message) } }
68 if version >= 0 { { let len = (self.entries).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.entries { for it in v { it.encode(buf, version)?; } } } }
69 if flex {
70 let tagged = WriteTaggedFields::new();
71 tagged.write(buf, &self.unknown_tagged_fields);
72 }
73 Ok(())
74 }
75 fn encoded_len(&self, version: i16) -> usize {
76 let flex = is_flexible(version);
77 let mut n: usize = 0;
78 if version >= 0 { n += 4; }
79 if version >= 0 { n += 2; }
80 if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message) } else { nullable_string_len(self.error_message) }; }
81 if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.entries).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
82 if flex {
83 let known_pairs: Vec<(u32, usize)> = Vec::new();
84 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
85 }
86 n
87 }
88}
89
90impl<'de> DecodeBorrow<'de> for DescribeClientQuotasResponse<'de> {
91 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
92 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
93 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
94 }
95 let flex = is_flexible(version);
96 let mut out = Self::default();
97 if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
98 if version >= 0 { out.error_code = get_i16(buf)?; }
99 if version >= 0 { out.error_message = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
100 if version >= 0 { out.entries = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(EntryData::decode_borrow(buf, version)?); } Some(v) } } }; }
101 if flex {
102 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
103 Ok(false)
104 })?;
105 }
106 Ok(out)
107 }
108}
109
110#[derive(Debug, Clone, PartialEq)]
111pub struct EntryData<'a> {
112 pub entity: Vec<EntityData<'a>>,
113 pub values: Vec<ValueData<'a>>,
114 pub unknown_tagged_fields: UnknownTaggedFields,
115}
116
117impl<'a> Default for EntryData<'a> {
118 fn default() -> Self {
119 Self {
120 entity: Vec::new(),
121 values: Vec::new(),
122 unknown_tagged_fields: Default::default(),
123 }
124 }
125}
126
127impl<'a> EntryData<'a> {
128 pub fn to_owned(&self) -> crate::owned::describe_client_quotas_response::EntryData {
129 crate::owned::describe_client_quotas_response::EntryData {
130 entity: (self.entity).iter().map(|it| it.to_owned()).collect(),
131 values: (self.values).iter().map(|it| it.to_owned()).collect(),
132 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
133 }
134 }
135}
136
137impl<'a> Encode for EntryData<'a> {
138 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
139 let flex = version >= 1;
140 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.entity).len(), flex); for it in &self.entity { it.encode(buf, version)?; } } }
141 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.values).len(), flex); for it in &self.values { it.encode(buf, version)?; } } }
142 if flex {
143 let tagged = WriteTaggedFields::new();
144 tagged.write(buf, &self.unknown_tagged_fields);
145 }
146 Ok(())
147 }
148 fn encoded_len(&self, version: i16) -> usize {
149 let flex = version >= 1;
150 let mut n: usize = 0;
151 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.entity).len(), flex); let body: usize = (self.entity).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
152 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.values).len(), flex); let body: usize = (self.values).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
153 if flex {
154 let known_pairs: Vec<(u32, usize)> = Vec::new();
155 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
156 }
157 n
158 }
159}
160
161impl<'de> DecodeBorrow<'de> for EntryData<'de> {
162 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
163 let flex = version >= 1;
164 let mut out = Self::default();
165 if version >= 0 { out.entity = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(EntityData::decode_borrow(buf, version)?); } v }; }
166 if version >= 0 { out.values = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(ValueData::decode_borrow(buf, version)?); } v }; }
167 if flex {
168 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
169 Ok(false)
170 })?;
171 }
172 Ok(out)
173 }
174}
175
176#[derive(Debug, Clone, PartialEq, Eq)]
177pub struct EntityData<'a> {
178 pub entity_type: &'a str,
179 pub entity_name: Option<&'a str>,
180 pub unknown_tagged_fields: UnknownTaggedFields,
181}
182
183impl<'a> Default for EntityData<'a> {
184 fn default() -> Self {
185 Self {
186 entity_type: "",
187 entity_name: None,
188 unknown_tagged_fields: Default::default(),
189 }
190 }
191}
192
193impl<'a> EntityData<'a> {
194 pub fn to_owned(&self) -> crate::owned::describe_client_quotas_response::EntityData {
195 crate::owned::describe_client_quotas_response::EntityData {
196 entity_type: (self.entity_type).to_string(),
197 entity_name: (self.entity_name).map(|s| s.to_string()),
198 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
199 }
200 }
201}
202
203impl<'a> Encode for EntityData<'a> {
204 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
205 let flex = version >= 1;
206 if version >= 0 { if flex { put_compact_string(buf, self.entity_type) } else { put_string(buf, self.entity_type) } }
207 if version >= 0 { if flex { put_compact_nullable_string(buf, self.entity_name) } else { put_nullable_string(buf, self.entity_name) } }
208 if flex {
209 let tagged = WriteTaggedFields::new();
210 tagged.write(buf, &self.unknown_tagged_fields);
211 }
212 Ok(())
213 }
214 fn encoded_len(&self, version: i16) -> usize {
215 let flex = version >= 1;
216 let mut n: usize = 0;
217 if version >= 0 { n += if flex { compact_string_len(self.entity_type) } else { string_len(self.entity_type) }; }
218 if version >= 0 { n += if flex { compact_nullable_string_len(self.entity_name) } else { nullable_string_len(self.entity_name) }; }
219 if flex {
220 let known_pairs: Vec<(u32, usize)> = Vec::new();
221 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
222 }
223 n
224 }
225}
226
227impl<'de> DecodeBorrow<'de> for EntityData<'de> {
228 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
229 let flex = version >= 1;
230 let mut out = Self::default();
231 if version >= 0 { out.entity_type = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
232 if version >= 0 { out.entity_name = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
233 if flex {
234 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
235 Ok(false)
236 })?;
237 }
238 Ok(out)
239 }
240}
241
242#[derive(Debug, Clone, PartialEq)]
243pub struct ValueData<'a> {
244 pub key: &'a str,
245 pub value: f64,
246 pub unknown_tagged_fields: UnknownTaggedFields,
247}
248
249impl<'a> Default for ValueData<'a> {
250 fn default() -> Self {
251 Self {
252 key: "",
253 value: 0.0f64,
254 unknown_tagged_fields: Default::default(),
255 }
256 }
257}
258
259impl<'a> ValueData<'a> {
260 pub fn to_owned(&self) -> crate::owned::describe_client_quotas_response::ValueData {
261 crate::owned::describe_client_quotas_response::ValueData {
262 key: (self.key).to_string(),
263 value: (self.value),
264 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
265 }
266 }
267}
268
269impl<'a> Encode for ValueData<'a> {
270 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
271 let flex = version >= 1;
272 if version >= 0 { if flex { put_compact_string(buf, self.key) } else { put_string(buf, self.key) } }
273 if version >= 0 { put_f64(buf, self.value) }
274 if flex {
275 let tagged = WriteTaggedFields::new();
276 tagged.write(buf, &self.unknown_tagged_fields);
277 }
278 Ok(())
279 }
280 fn encoded_len(&self, version: i16) -> usize {
281 let flex = version >= 1;
282 let mut n: usize = 0;
283 if version >= 0 { n += if flex { compact_string_len(self.key) } else { string_len(self.key) }; }
284 if version >= 0 { n += 8; }
285 if flex {
286 let known_pairs: Vec<(u32, usize)> = Vec::new();
287 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
288 }
289 n
290 }
291}
292
293impl<'de> DecodeBorrow<'de> for ValueData<'de> {
294 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
295 let flex = version >= 1;
296 let mut out = Self::default();
297 if version >= 0 { out.key = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
298 if version >= 0 { out.value = get_f64(buf)?; }
299 if flex {
300 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
301 Ok(false)
302 })?;
303 }
304 Ok(out)
305 }
306}