Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AlterClientQuotasRequest.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, 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, 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 = 49;
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 AlterClientQuotasRequest {
25    pub entries: Vec<EntryData>,
26    pub validate_only: bool,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29
30impl Encode for AlterClientQuotasRequest {
31    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
32        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
33            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
34        }
35        let flex = is_flexible(version);
36        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.entries).len(), flex); for it in &self.entries { it.encode(buf, version)?; } } }
37        if version >= 0 { put_bool(buf, self.validate_only) }
38        if flex {
39            let tagged = WriteTaggedFields::new();
40            tagged.write(buf, &self.unknown_tagged_fields);
41        }
42        Ok(())
43    }
44    fn encoded_len(&self, version: i16) -> usize {
45        let flex = is_flexible(version);
46        let mut n: usize = 0;
47        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 }; }
48        if version >= 0 { n += 1; }
49        if flex {
50            let known_pairs: Vec<(u32, usize)> = Vec::new();
51            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
52        }
53        n
54    }
55}
56
57impl<'de> Decode<'de> for AlterClientQuotasRequest {
58    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
59        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
60            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
61        }
62        let flex = is_flexible(version);
63        let mut out = Self::default();
64        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(buf, version)?); } v }; }
65        if version >= 0 { out.validate_only = get_bool(buf)?; }
66        if flex {
67            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
68                Ok(false)
69            })?;
70        }
71        Ok(out)
72    }
73}
74
75#[derive(Debug, Clone, PartialEq, Default)]
76pub struct EntryData {
77    pub entity: Vec<EntityData>,
78    pub ops: Vec<OpData>,
79    pub unknown_tagged_fields: UnknownTaggedFields,
80}
81
82impl Encode for EntryData {
83    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
84        let flex = version >= 1;
85        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.entity).len(), flex); for it in &self.entity { it.encode(buf, version)?; } } }
86        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.ops).len(), flex); for it in &self.ops { it.encode(buf, version)?; } } }
87        if flex {
88            let tagged = WriteTaggedFields::new();
89            tagged.write(buf, &self.unknown_tagged_fields);
90        }
91        Ok(())
92    }
93    fn encoded_len(&self, version: i16) -> usize {
94        let flex = version >= 1;
95        let mut n: usize = 0;
96        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 }; }
97        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 }; }
98        if flex {
99            let known_pairs: Vec<(u32, usize)> = Vec::new();
100            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
101        }
102        n
103    }
104}
105
106impl<'de> Decode<'de> for EntryData {
107    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
108        let flex = version >= 1;
109        let mut out = Self::default();
110        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 }; }
111        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(buf, version)?); } v }; }
112        if flex {
113            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
114                Ok(false)
115            })?;
116        }
117        Ok(out)
118    }
119}
120
121#[derive(Debug, Clone, PartialEq, Eq, Default)]
122pub struct EntityData {
123    pub entity_type: String,
124    pub entity_name: Option<String>,
125    pub unknown_tagged_fields: UnknownTaggedFields,
126}
127
128impl Encode for EntityData {
129    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
130        let flex = version >= 1;
131        if version >= 0 { if flex { put_compact_string(buf, &self.entity_type) } else { put_string(buf, &self.entity_type) } }
132        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()) } }
133        if flex {
134            let tagged = WriteTaggedFields::new();
135            tagged.write(buf, &self.unknown_tagged_fields);
136        }
137        Ok(())
138    }
139    fn encoded_len(&self, version: i16) -> usize {
140        let flex = version >= 1;
141        let mut n: usize = 0;
142        if version >= 0 { n += if flex { compact_string_len(&self.entity_type) } else { string_len(&self.entity_type) }; }
143        if version >= 0 { n += if flex { compact_nullable_string_len(self.entity_name.as_deref()) } else { nullable_string_len(self.entity_name.as_deref()) }; }
144        if flex {
145            let known_pairs: Vec<(u32, usize)> = Vec::new();
146            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
147        }
148        n
149    }
150}
151
152impl<'de> Decode<'de> for EntityData {
153    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
154        let flex = version >= 1;
155        let mut out = Self::default();
156        if version >= 0 { out.entity_type = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
157        if version >= 0 { out.entity_name = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
158        if flex {
159            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
160                Ok(false)
161            })?;
162        }
163        Ok(out)
164    }
165}
166
167#[derive(Debug, Clone, PartialEq, Default)]
168pub struct OpData {
169    pub key: String,
170    pub value: f64,
171    pub remove: bool,
172    pub unknown_tagged_fields: UnknownTaggedFields,
173}
174
175impl Encode for OpData {
176    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
177        let flex = version >= 1;
178        if version >= 0 { if flex { put_compact_string(buf, &self.key) } else { put_string(buf, &self.key) } }
179        if version >= 0 { put_f64(buf, self.value) }
180        if version >= 0 { put_bool(buf, self.remove) }
181        if flex {
182            let tagged = WriteTaggedFields::new();
183            tagged.write(buf, &self.unknown_tagged_fields);
184        }
185        Ok(())
186    }
187    fn encoded_len(&self, version: i16) -> usize {
188        let flex = version >= 1;
189        let mut n: usize = 0;
190        if version >= 0 { n += if flex { compact_string_len(&self.key) } else { string_len(&self.key) }; }
191        if version >= 0 { n += 8; }
192        if version >= 0 { n += 1; }
193        if flex {
194            let known_pairs: Vec<(u32, usize)> = Vec::new();
195            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
196        }
197        n
198    }
199}
200
201impl<'de> Decode<'de> for OpData {
202    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
203        let flex = version >= 1;
204        let mut out = Self::default();
205        if version >= 0 { out.key = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
206        if version >= 0 { out.value = get_f64(buf)?; }
207        if version >= 0 { out.remove = get_bool(buf)?; }
208        if flex {
209            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
210                Ok(false)
211            })?;
212        }
213        Ok(out)
214    }
215}
216
217/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
218/// Only includes fields valid for the given version.
219#[must_use]
220#[allow(unused_comparisons)]
221pub fn default_json(version: i16) -> ::serde_json::Value {
222    let mut obj = ::serde_json::Map::new();
223    obj.insert("entries".to_string(), ::serde_json::Value::Array(vec![]));
224    obj.insert("validateOnly".to_string(), ::serde_json::Value::Bool(false));
225    ::serde_json::Value::Object(obj)
226}
227
228impl crate::ProtocolRequest for AlterClientQuotasRequest {
229    const API_KEY: i16 = API_KEY;
230    const MIN_VERSION: i16 = MIN_VERSION;
231    const MAX_VERSION: i16 = MAX_VERSION;
232    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
233    type Response = super::alter_client_quotas_response::AlterClientQuotasResponse;
234}