Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
ClientQuotaRecord.owned.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::{
6    Decode, Encode, ProtocolError, UnknownTaggedFields,
7    primitives::{
8        fixed::{get_bool, get_f64, put_bool, put_f64},
9        string_bytes::{
10            compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
11            get_compact_string_owned, get_nullable_string_owned, get_string_owned,
12            nullable_string_len, put_compact_nullable_string, put_compact_string,
13            put_nullable_string, put_string, string_len,
14        },
15    },
16    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const MIN_VERSION: i16 = 0;
19pub const MAX_VERSION: i16 = 0;
20pub const FLEXIBLE_MIN: i16 = 0;
21#[inline]
22#[must_use]
23pub fn is_flexible(version: i16) -> bool {
24    version >= FLEXIBLE_MIN
25}
26#[derive(Debug, Clone, PartialEq, Default)]
27pub struct ClientQuotaRecord {
28    pub entity: Vec<EntityData>,
29    pub key: String,
30    pub value: f64,
31    pub remove: bool,
32    pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Encode for ClientQuotaRecord {
35    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
36        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
37            return Err(ProtocolError::SchemaMismatch(
38                "ClientQuotaRecord version out of range",
39            ));
40        }
41        let flex = is_flexible(version);
42        if version >= 0 {
43            {
44                crate::primitives::array::put_array_len(buf, (self.entity).len(), flex);
45                for it in &self.entity {
46                    it.encode(buf, version)?;
47                }
48            };
49        }
50        if version >= 0 {
51            if flex {
52                let () = put_compact_string(buf, &self.key);
53            } else {
54                let () = put_string(buf, &self.key);
55            }
56        }
57        if version >= 0 {
58            put_f64(buf, self.value);
59        }
60        if version >= 0 {
61            put_bool(buf, self.remove);
62        }
63        if flex {
64            let tagged = WriteTaggedFields::new();
65            tagged.write(buf, &self.unknown_tagged_fields);
66        }
67        Ok(())
68    }
69    fn encoded_len(&self, version: i16) -> usize {
70        let flex = is_flexible(version);
71        let mut n: usize = 0;
72        if version >= 0 {
73            n += {
74                let prefix =
75                    crate::primitives::array::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 = crate::primitives::array::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_string();
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                let () = put_compact_string(buf, &self.entity_type);
179            } else {
180                let () = put_string(buf, &self.entity_type);
181            }
182        }
183        if version >= 0 {
184            if flex {
185                let () = put_compact_nullable_string(buf, self.entity_name.as_deref());
186            } else {
187                let () = 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_string();
251        }
252        if version >= 0 {
253            m.entity_name = Some("x".to_string());
254        }
255        m
256    }
257}
258/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
259/// Only includes fields valid for the given version.
260#[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_string(), ::serde_json::Value::Array(vec![]));
265    obj.insert(
266        "key".to_string(),
267        ::serde_json::Value::String(String::new()),
268    );
269    obj.insert("value".to_string(), ::serde_json::json!(0.0));
270    obj.insert("remove".to_string(), ::serde_json::Value::Bool(false));
271    ::serde_json::Value::Object(obj)
272}