Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
CreateAclsResponse.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_i16, get_i32, put_i16, put_i32},
9        string_bytes::{
10            compact_nullable_string_len, get_compact_nullable_string_owned,
11            get_nullable_string_owned, nullable_string_len, put_compact_nullable_string,
12            put_nullable_string,
13        },
14    },
15    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
16};
17pub const API_KEY: i16 = 30;
18pub const MIN_VERSION: i16 = 1;
19pub const MAX_VERSION: i16 = 3;
20pub const FLEXIBLE_MIN: i16 = 2;
21#[inline]
22#[must_use]
23pub fn is_flexible(version: i16) -> bool {
24    version >= FLEXIBLE_MIN
25}
26#[derive(Debug, Clone, PartialEq, Eq, Default)]
27pub struct CreateAclsResponse {
28    pub throttle_time_ms: i32,
29    pub results: Vec<AclCreationResult>,
30    pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl Encode for CreateAclsResponse {
33    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
34        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
35            return Err(ProtocolError::UnsupportedVersion {
36                api_key: API_KEY,
37                version,
38            });
39        }
40        let flex = is_flexible(version);
41        if version >= 0 {
42            put_i32(buf, self.throttle_time_ms);
43        }
44        if version >= 0 {
45            {
46                crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
47                for it in &self.results {
48                    it.encode(buf, version)?;
49                }
50            };
51        }
52        if flex {
53            let tagged = WriteTaggedFields::new();
54            tagged.write(buf, &self.unknown_tagged_fields);
55        }
56        Ok(())
57    }
58    fn encoded_len(&self, version: i16) -> usize {
59        let flex = is_flexible(version);
60        let mut n: usize = 0;
61        if version >= 0 {
62            n += 4;
63        }
64        if version >= 0 {
65            n += {
66                let prefix =
67                    crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
68                let body: usize = (self.results)
69                    .iter()
70                    .map(|it| it.encoded_len(version))
71                    .sum();
72                prefix + body
73            };
74        }
75        if flex {
76            let known_pairs: Vec<(u32, usize)> = Vec::new();
77            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
78        }
79        n
80    }
81}
82impl Decode<'_> for CreateAclsResponse {
83    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
84        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
85            return Err(ProtocolError::UnsupportedVersion {
86                api_key: API_KEY,
87                version,
88            });
89        }
90        let flex = is_flexible(version);
91        let mut out = Self::default();
92        if version >= 0 {
93            out.throttle_time_ms = get_i32(buf)?;
94        }
95        if version >= 0 {
96            out.results = {
97                let n = crate::primitives::array::get_array_len(buf, flex)?;
98                let mut v = Vec::with_capacity(n);
99                for _ in 0..n {
100                    v.push(AclCreationResult::decode(buf, version)?);
101                }
102                v
103            };
104        }
105        if flex {
106            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
107        }
108        Ok(out)
109    }
110}
111#[cfg(test)]
112impl CreateAclsResponse {
113    #[must_use]
114    pub fn populated(version: i16) -> Self {
115        let mut m = Self::default();
116        if version >= 0 {
117            m.throttle_time_ms = 1i32;
118        }
119        if version >= 0 {
120            m.results = vec![AclCreationResult::populated(version)];
121        }
122        m
123    }
124}
125#[derive(Debug, Clone, PartialEq, Eq)]
126pub struct AclCreationResult {
127    pub error_code: i16,
128    pub error_message: Option<String>,
129    pub unknown_tagged_fields: UnknownTaggedFields,
130}
131impl Default for AclCreationResult {
132    fn default() -> Self {
133        Self {
134            error_code: 0i16,
135            error_message: Some(String::new()),
136            unknown_tagged_fields: UnknownTaggedFields::default(),
137        }
138    }
139}
140impl Encode for AclCreationResult {
141    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
142        let flex = version >= 2;
143        if version >= 0 {
144            put_i16(buf, self.error_code);
145        }
146        if version >= 0 {
147            if flex {
148                let () = put_compact_nullable_string(buf, self.error_message.as_deref());
149            } else {
150                let () = put_nullable_string(buf, self.error_message.as_deref());
151            }
152        }
153        if flex {
154            let tagged = WriteTaggedFields::new();
155            tagged.write(buf, &self.unknown_tagged_fields);
156        }
157        Ok(())
158    }
159    fn encoded_len(&self, version: i16) -> usize {
160        let flex = version >= 2;
161        let mut n: usize = 0;
162        if version >= 0 {
163            n += 2;
164        }
165        if version >= 0 {
166            n += if flex {
167                compact_nullable_string_len(self.error_message.as_deref())
168            } else {
169                nullable_string_len(self.error_message.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 AclCreationResult {
180    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
181        let flex = version >= 2;
182        let mut out = Self::default();
183        if version >= 0 {
184            out.error_code = get_i16(buf)?;
185        }
186        if version >= 0 {
187            out.error_message = if flex {
188                get_compact_nullable_string_owned(buf)?
189            } else {
190                get_nullable_string_owned(buf)?
191            };
192        }
193        if flex {
194            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
195        }
196        Ok(out)
197    }
198}
199#[cfg(test)]
200impl AclCreationResult {
201    #[must_use]
202    pub fn populated(version: i16) -> Self {
203        let mut m = Self::default();
204        if version >= 0 {
205            m.error_code = 1i16;
206        }
207        if version >= 0 {
208            m.error_message = Some("x".to_string());
209        }
210        m
211    }
212}
213/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
214/// Only includes fields valid for the given version.
215#[must_use]
216#[allow(unused_comparisons)]
217pub fn default_json(_version: i16) -> ::serde_json::Value {
218    let mut obj = ::serde_json::Map::new();
219    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
220    obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
221    ::serde_json::Value::Object(obj)
222}