Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AlterClientQuotasResponse.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
6use crate::primitives::string_bytes::{
7    compact_nullable_string_len, compact_string_len, nullable_string_len,
8    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
9    string_len,
10};
11use crate::primitives::string_bytes_borrowed::{
12    get_compact_nullable_string_borrowed, get_compact_string_borrowed,
13    get_nullable_string_borrowed, get_string_borrowed,
14};
15use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
16use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
17
18pub const API_KEY: i16 = 49;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 1;
21pub const FLEXIBLE_MIN: i16 = 1;
22
23#[inline]
24fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
25
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct AlterClientQuotasResponse<'a> {
28    pub throttle_time_ms: i32,
29    pub entries: Vec<EntryData<'a>>,
30    pub unknown_tagged_fields: UnknownTaggedFields,
31}
32
33impl<'a> Default for AlterClientQuotasResponse<'a> {
34    fn default() -> Self {
35        Self {
36            throttle_time_ms: 0i32,
37            entries: Vec::new(),
38            unknown_tagged_fields: Default::default(),
39        }
40    }
41}
42
43impl<'a> AlterClientQuotasResponse<'a> {
44    pub fn to_owned(&self) -> crate::owned::alter_client_quotas_response::AlterClientQuotasResponse {
45        crate::owned::alter_client_quotas_response::AlterClientQuotasResponse {
46            throttle_time_ms: (self.throttle_time_ms),
47            entries: (self.entries).iter().map(|it| it.to_owned()).collect(),
48            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
49        }
50    }
51}
52
53impl<'a> Encode for AlterClientQuotasResponse<'a> {
54    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
55        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
56            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
57        }
58        let flex = is_flexible(version);
59        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
60        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.entries).len(), flex); for it in &self.entries { it.encode(buf, version)?; } } }
61        if flex {
62            let tagged = WriteTaggedFields::new();
63            tagged.write(buf, &self.unknown_tagged_fields);
64        }
65        Ok(())
66    }
67    fn encoded_len(&self, version: i16) -> usize {
68        let flex = is_flexible(version);
69        let mut n: usize = 0;
70        if version >= 0 { n += 4; }
71        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 }; }
72        if flex {
73            let known_pairs: Vec<(u32, usize)> = Vec::new();
74            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
75        }
76        n
77    }
78}
79
80impl<'de> DecodeBorrow<'de> for AlterClientQuotasResponse<'de> {
81    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
82        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
83            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
84        }
85        let flex = is_flexible(version);
86        let mut out = Self::default();
87        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
88        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_borrow(buf, version)?); } v }; }
89        if flex {
90            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
91                Ok(false)
92            })?;
93        }
94        Ok(out)
95    }
96}
97
98#[derive(Debug, Clone, PartialEq, Eq)]
99pub struct EntryData<'a> {
100    pub error_code: i16,
101    pub error_message: Option<&'a str>,
102    pub entity: Vec<EntityData<'a>>,
103    pub unknown_tagged_fields: UnknownTaggedFields,
104}
105
106impl<'a> Default for EntryData<'a> {
107    fn default() -> Self {
108        Self {
109            error_code: 0i16,
110            error_message: None,
111            entity: Vec::new(),
112            unknown_tagged_fields: Default::default(),
113        }
114    }
115}
116
117impl<'a> EntryData<'a> {
118    pub fn to_owned(&self) -> crate::owned::alter_client_quotas_response::EntryData {
119        crate::owned::alter_client_quotas_response::EntryData {
120            error_code: (self.error_code),
121            error_message: (self.error_message).map(|s| s.to_string()),
122            entity: (self.entity).iter().map(|it| it.to_owned()).collect(),
123            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
124        }
125    }
126}
127
128impl<'a> Encode for EntryData<'a> {
129    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
130        let flex = version >= 1;
131        if version >= 0 { put_i16(buf, self.error_code) }
132        if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message) } else { put_nullable_string(buf, self.error_message) } }
133        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.entity).len(), flex); for it in &self.entity { it.encode(buf, version)?; } } }
134        if flex {
135            let tagged = WriteTaggedFields::new();
136            tagged.write(buf, &self.unknown_tagged_fields);
137        }
138        Ok(())
139    }
140    fn encoded_len(&self, version: i16) -> usize {
141        let flex = version >= 1;
142        let mut n: usize = 0;
143        if version >= 0 { n += 2; }
144        if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message) } else { nullable_string_len(self.error_message) }; }
145        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 }; }
146        if flex {
147            let known_pairs: Vec<(u32, usize)> = Vec::new();
148            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
149        }
150        n
151    }
152}
153
154impl<'de> DecodeBorrow<'de> for EntryData<'de> {
155    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
156        let flex = version >= 1;
157        let mut out = Self::default();
158        if version >= 0 { out.error_code = get_i16(buf)?; }
159        if version >= 0 { out.error_message = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
160        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_borrow(buf, version)?); } v }; }
161        if flex {
162            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
163                Ok(false)
164            })?;
165        }
166        Ok(out)
167    }
168}
169
170#[derive(Debug, Clone, PartialEq, Eq)]
171pub struct EntityData<'a> {
172    pub entity_type: &'a str,
173    pub entity_name: Option<&'a str>,
174    pub unknown_tagged_fields: UnknownTaggedFields,
175}
176
177impl<'a> Default for EntityData<'a> {
178    fn default() -> Self {
179        Self {
180            entity_type: "",
181            entity_name: None,
182            unknown_tagged_fields: Default::default(),
183        }
184    }
185}
186
187impl<'a> EntityData<'a> {
188    pub fn to_owned(&self) -> crate::owned::alter_client_quotas_response::EntityData {
189        crate::owned::alter_client_quotas_response::EntityData {
190            entity_type: (self.entity_type).to_string(),
191            entity_name: (self.entity_name).map(|s| s.to_string()),
192            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
193        }
194    }
195}
196
197impl<'a> Encode for EntityData<'a> {
198    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
199        let flex = version >= 1;
200        if version >= 0 { if flex { put_compact_string(buf, self.entity_type) } else { put_string(buf, self.entity_type) } }
201        if version >= 0 { if flex { put_compact_nullable_string(buf, self.entity_name) } else { put_nullable_string(buf, self.entity_name) } }
202        if flex {
203            let tagged = WriteTaggedFields::new();
204            tagged.write(buf, &self.unknown_tagged_fields);
205        }
206        Ok(())
207    }
208    fn encoded_len(&self, version: i16) -> usize {
209        let flex = version >= 1;
210        let mut n: usize = 0;
211        if version >= 0 { n += if flex { compact_string_len(self.entity_type) } else { string_len(self.entity_type) }; }
212        if version >= 0 { n += if flex { compact_nullable_string_len(self.entity_name) } else { nullable_string_len(self.entity_name) }; }
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}
220
221impl<'de> DecodeBorrow<'de> for EntityData<'de> {
222    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
223        let flex = version >= 1;
224        let mut out = Self::default();
225        if version >= 0 { out.entity_type = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
226        if version >= 0 { out.entity_name = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
227        if flex {
228            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
229                Ok(false)
230            })?;
231        }
232        Ok(out)
233    }
234}