Skip to main content

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

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