krabka_protocol/opt/rustwide/workdir/generated/
AlterConfigsResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 fixed::{get_i8, get_i16, get_i32, put_i8, put_i16, put_i32},
9 string_bytes::{
10 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
11 get_compact_string_owned, get_nullable_string_owned, get_string_owned,
12 nullable_string_len, put_compact_nullable_string, put_compact_string,
13 put_nullable_string, put_string, string_len,
14 },
15 },
16 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const API_KEY: i16 = 33;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 2;
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 AlterConfigsResponse {
29 pub throttle_time_ms: i32,
30 pub responses: Vec<AlterConfigsResourceResponse>,
31 pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl Encode for AlterConfigsResponse {
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 crate::primitives::array::put_array_len(buf, (self.responses).len(), flex);
48 for it in &self.responses {
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 =
68 crate::primitives::array::array_len_prefix_len((self.responses).len(), flex);
69 let body: usize = (self.responses)
70 .iter()
71 .map(|it| it.encoded_len(version))
72 .sum();
73 prefix + body
74 };
75 }
76 if flex {
77 let known_pairs: Vec<(u32, usize)> = Vec::new();
78 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
79 }
80 n
81 }
82}
83impl Decode<'_> for AlterConfigsResponse {
84 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
85 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
86 return Err(ProtocolError::UnsupportedVersion {
87 api_key: API_KEY,
88 version,
89 });
90 }
91 let flex = is_flexible(version);
92 let mut out = Self::default();
93 if version >= 0 {
94 out.throttle_time_ms = get_i32(buf)?;
95 }
96 if version >= 0 {
97 out.responses = {
98 let n = crate::primitives::array::get_array_len(buf, flex)?;
99 let mut v = Vec::with_capacity(n);
100 for _ in 0..n {
101 v.push(AlterConfigsResourceResponse::decode(buf, version)?);
102 }
103 v
104 };
105 }
106 if flex {
107 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
108 }
109 Ok(out)
110 }
111}
112#[cfg(test)]
113impl AlterConfigsResponse {
114 #[must_use]
115 pub fn populated(version: i16) -> Self {
116 let mut m = Self::default();
117 if version >= 0 {
118 m.throttle_time_ms = 1i32;
119 }
120 if version >= 0 {
121 m.responses = vec![AlterConfigsResourceResponse::populated(version)];
122 }
123 m
124 }
125}
126#[derive(Debug, Clone, PartialEq, Eq)]
127pub struct AlterConfigsResourceResponse {
128 pub error_code: i16,
129 pub error_message: Option<String>,
130 pub resource_type: i8,
131 pub resource_name: String,
132 pub unknown_tagged_fields: UnknownTaggedFields,
133}
134impl Default for AlterConfigsResourceResponse {
135 fn default() -> Self {
136 Self {
137 error_code: 0i16,
138 error_message: Some(String::new()),
139 resource_type: 0i8,
140 resource_name: String::new(),
141 unknown_tagged_fields: UnknownTaggedFields::default(),
142 }
143 }
144}
145impl Encode for AlterConfigsResourceResponse {
146 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
147 let flex = version >= 2;
148 if version >= 0 {
149 put_i16(buf, self.error_code);
150 }
151 if version >= 0 {
152 if flex {
153 let () = put_compact_nullable_string(buf, self.error_message.as_deref());
154 } else {
155 let () = put_nullable_string(buf, self.error_message.as_deref());
156 }
157 }
158 if version >= 0 {
159 put_i8(buf, self.resource_type);
160 }
161 if version >= 0 {
162 if flex {
163 let () = put_compact_string(buf, &self.resource_name);
164 } else {
165 let () = put_string(buf, &self.resource_name);
166 }
167 }
168 if flex {
169 let tagged = WriteTaggedFields::new();
170 tagged.write(buf, &self.unknown_tagged_fields);
171 }
172 Ok(())
173 }
174 fn encoded_len(&self, version: i16) -> usize {
175 let flex = version >= 2;
176 let mut n: usize = 0;
177 if version >= 0 {
178 n += 2;
179 }
180 if version >= 0 {
181 n += if flex {
182 compact_nullable_string_len(self.error_message.as_deref())
183 } else {
184 nullable_string_len(self.error_message.as_deref())
185 };
186 }
187 if version >= 0 {
188 n += 1;
189 }
190 if version >= 0 {
191 n += if flex {
192 compact_string_len(&self.resource_name)
193 } else {
194 string_len(&self.resource_name)
195 };
196 }
197 if flex {
198 let known_pairs: Vec<(u32, usize)> = Vec::new();
199 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
200 }
201 n
202 }
203}
204impl Decode<'_> for AlterConfigsResourceResponse {
205 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
206 let flex = version >= 2;
207 let mut out = Self::default();
208 if version >= 0 {
209 out.error_code = get_i16(buf)?;
210 }
211 if version >= 0 {
212 out.error_message = if flex {
213 get_compact_nullable_string_owned(buf)?
214 } else {
215 get_nullable_string_owned(buf)?
216 };
217 }
218 if version >= 0 {
219 out.resource_type = get_i8(buf)?;
220 }
221 if version >= 0 {
222 out.resource_name = if flex {
223 get_compact_string_owned(buf)?
224 } else {
225 get_string_owned(buf)?
226 };
227 }
228 if flex {
229 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
230 }
231 Ok(out)
232 }
233}
234#[cfg(test)]
235impl AlterConfigsResourceResponse {
236 #[must_use]
237 pub fn populated(version: i16) -> Self {
238 let mut m = Self::default();
239 if version >= 0 {
240 m.error_code = 1i16;
241 }
242 if version >= 0 {
243 m.error_message = Some("x".to_string());
244 }
245 if version >= 0 {
246 m.resource_type = 1i8;
247 }
248 if version >= 0 {
249 m.resource_name = "x".to_string();
250 }
251 m
252 }
253}
254#[must_use]
257#[allow(unused_comparisons)]
258pub fn default_json(_version: i16) -> ::serde_json::Value {
259 let mut obj = ::serde_json::Map::new();
260 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
261 obj.insert("responses".to_string(), ::serde_json::Value::Array(vec![]));
262 ::serde_json::Value::Object(obj)
263}