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