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