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