krabka_protocol/opt/rustwide/workdir/generated/
CreateAclsResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 array::{array_len_prefix_len, get_array_len, put_array_len},
9 fixed::{get_i16, get_i32, put_i16, put_i32},
10 string_bytes::{
11 compact_nullable_string_len, get_compact_nullable_string_owned,
12 get_nullable_string_owned, nullable_string_len, put_compact_nullable_string,
13 put_nullable_string,
14 },
15 },
16 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const API_KEY: i16 = 30;
19pub const MIN_VERSION: i16 = 1;
20pub const MAX_VERSION: i16 = 3;
21pub const FLEXIBLE_MIN: i16 = 2;
22#[inline]
23#[must_use]
24pub fn is_flexible(version: i16) -> bool {
25 version >= FLEXIBLE_MIN
26}
27#[derive(Debug, Clone, PartialEq, Eq, Default)]
28pub struct CreateAclsResponse {
29 pub throttle_time_ms: i32,
30 pub results: Vec<AclCreationResult>,
31 pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl Encode for CreateAclsResponse {
34 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
35 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
36 return Err(ProtocolError::UnsupportedVersion {
37 api_key: API_KEY,
38 version,
39 });
40 }
41 let flex = is_flexible(version);
42 if version >= 0 {
43 put_i32(buf, self.throttle_time_ms);
44 }
45 if version >= 0 {
46 {
47 put_array_len(buf, (self.results).len(), flex)?;
48 for it in &self.results {
49 it.encode(buf, version)?;
50 }
51 }
52 }
53 if flex {
54 let tagged = WriteTaggedFields::new();
55 tagged.write(buf, &self.unknown_tagged_fields)?;
56 }
57 Ok(())
58 }
59 fn encoded_len(&self, version: i16) -> usize {
60 let flex = is_flexible(version);
61 let mut n: usize = 0;
62 if version >= 0 {
63 n += 4;
64 }
65 if version >= 0 {
66 n += {
67 let prefix = 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 = 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 put_compact_nullable_string(buf, self.error_message.as_deref())?;
149 } else {
150 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_owned());
209 }
210 m
211 }
212}
213#[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_owned(), ::serde_json::json!(0));
220 obj.insert("results".to_owned(), ::serde_json::Value::Array(vec![]));
221 ::serde_json::Value::Object(obj)
222}