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