Skip to main content

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