crabka_protocol/opt/rustwide/workdir/generated/
DescribeClientQuotasResponse.owned.rs1use bytes::{Buf, 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, get_compact_nullable_string_owned,
8 get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
10 string_len,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 48;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 1;
18pub const FLEXIBLE_MIN: i16 = 1;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Default)]
24pub struct DescribeClientQuotasResponse {
25 pub throttle_time_ms: i32,
26 pub error_code: i16,
27 pub error_message: Option<String>,
28 pub entries: Option<Vec<EntryData>>,
29 pub unknown_tagged_fields: UnknownTaggedFields,
30}
31
32impl Encode for DescribeClientQuotasResponse {
33 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
34 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
35 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
36 }
37 let flex = is_flexible(version);
38 if version >= 0 { put_i32(buf, self.throttle_time_ms) }
39 if version >= 0 { put_i16(buf, self.error_code) }
40 if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message.as_deref()) } else { put_nullable_string(buf, self.error_message.as_deref()) } }
41 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)?; } } } }
42 if flex {
43 let tagged = WriteTaggedFields::new();
44 tagged.write(buf, &self.unknown_tagged_fields);
45 }
46 Ok(())
47 }
48 fn encoded_len(&self, version: i16) -> usize {
49 let flex = is_flexible(version);
50 let mut n: usize = 0;
51 if version >= 0 { n += 4; }
52 if version >= 0 { n += 2; }
53 if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message.as_deref()) } else { nullable_string_len(self.error_message.as_deref()) }; }
54 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 }; }
55 if flex {
56 let known_pairs: Vec<(u32, usize)> = Vec::new();
57 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
58 }
59 n
60 }
61}
62
63impl<'de> Decode<'de> for DescribeClientQuotasResponse {
64 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
65 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
66 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
67 }
68 let flex = is_flexible(version);
69 let mut out = Self::default();
70 if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
71 if version >= 0 { out.error_code = get_i16(buf)?; }
72 if version >= 0 { out.error_message = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
73 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(buf, version)?); } Some(v) } } }; }
74 if flex {
75 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
76 Ok(false)
77 })?;
78 }
79 Ok(out)
80 }
81}
82
83#[derive(Debug, Clone, PartialEq, Default)]
84pub struct EntryData {
85 pub entity: Vec<EntityData>,
86 pub values: Vec<ValueData>,
87 pub unknown_tagged_fields: UnknownTaggedFields,
88}
89
90impl Encode for EntryData {
91 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
92 let flex = version >= 1;
93 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.entity).len(), flex); for it in &self.entity { it.encode(buf, version)?; } } }
94 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.values).len(), flex); for it in &self.values { it.encode(buf, version)?; } } }
95 if flex {
96 let tagged = WriteTaggedFields::new();
97 tagged.write(buf, &self.unknown_tagged_fields);
98 }
99 Ok(())
100 }
101 fn encoded_len(&self, version: i16) -> usize {
102 let flex = version >= 1;
103 let mut n: usize = 0;
104 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 }; }
105 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 }; }
106 if flex {
107 let known_pairs: Vec<(u32, usize)> = Vec::new();
108 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
109 }
110 n
111 }
112}
113
114impl<'de> Decode<'de> for EntryData {
115 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
116 let flex = version >= 1;
117 let mut out = Self::default();
118 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(buf, version)?); } v }; }
119 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(buf, version)?); } v }; }
120 if flex {
121 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
122 Ok(false)
123 })?;
124 }
125 Ok(out)
126 }
127}
128
129#[derive(Debug, Clone, PartialEq, Eq, Default)]
130pub struct EntityData {
131 pub entity_type: String,
132 pub entity_name: Option<String>,
133 pub unknown_tagged_fields: UnknownTaggedFields,
134}
135
136impl Encode for EntityData {
137 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
138 let flex = version >= 1;
139 if version >= 0 { if flex { put_compact_string(buf, &self.entity_type) } else { put_string(buf, &self.entity_type) } }
140 if version >= 0 { if flex { put_compact_nullable_string(buf, self.entity_name.as_deref()) } else { put_nullable_string(buf, self.entity_name.as_deref()) } }
141 if flex {
142 let tagged = WriteTaggedFields::new();
143 tagged.write(buf, &self.unknown_tagged_fields);
144 }
145 Ok(())
146 }
147 fn encoded_len(&self, version: i16) -> usize {
148 let flex = version >= 1;
149 let mut n: usize = 0;
150 if version >= 0 { n += if flex { compact_string_len(&self.entity_type) } else { string_len(&self.entity_type) }; }
151 if version >= 0 { n += if flex { compact_nullable_string_len(self.entity_name.as_deref()) } else { nullable_string_len(self.entity_name.as_deref()) }; }
152 if flex {
153 let known_pairs: Vec<(u32, usize)> = Vec::new();
154 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
155 }
156 n
157 }
158}
159
160impl<'de> Decode<'de> for EntityData {
161 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
162 let flex = version >= 1;
163 let mut out = Self::default();
164 if version >= 0 { out.entity_type = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
165 if version >= 0 { out.entity_name = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
166 if flex {
167 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
168 Ok(false)
169 })?;
170 }
171 Ok(out)
172 }
173}
174
175#[derive(Debug, Clone, PartialEq, Default)]
176pub struct ValueData {
177 pub key: String,
178 pub value: f64,
179 pub unknown_tagged_fields: UnknownTaggedFields,
180}
181
182impl Encode for ValueData {
183 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
184 let flex = version >= 1;
185 if version >= 0 { if flex { put_compact_string(buf, &self.key) } else { put_string(buf, &self.key) } }
186 if version >= 0 { put_f64(buf, self.value) }
187 if flex {
188 let tagged = WriteTaggedFields::new();
189 tagged.write(buf, &self.unknown_tagged_fields);
190 }
191 Ok(())
192 }
193 fn encoded_len(&self, version: i16) -> usize {
194 let flex = version >= 1;
195 let mut n: usize = 0;
196 if version >= 0 { n += if flex { compact_string_len(&self.key) } else { string_len(&self.key) }; }
197 if version >= 0 { n += 8; }
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}
205
206impl<'de> Decode<'de> for ValueData {
207 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
208 let flex = version >= 1;
209 let mut out = Self::default();
210 if version >= 0 { out.key = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
211 if version >= 0 { out.value = get_f64(buf)?; }
212 if flex {
213 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
214 Ok(false)
215 })?;
216 }
217 Ok(out)
218 }
219}
220
221#[must_use]
224#[allow(unused_comparisons)]
225pub fn default_json(version: i16) -> ::serde_json::Value {
226 let mut obj = ::serde_json::Map::new();
227 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
228 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
229 obj.insert("errorMessage".to_string(), ::serde_json::Value::Null);
230 obj.insert("entries".to_string(), ::serde_json::Value::Null);
231 ::serde_json::Value::Object(obj)
232}