krabka_protocol/opt/rustwide/workdir/generated/
AlterReplicaLogDirsResponse.owned.rs1use 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_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
11 put_string, string_len,
12 },
13 },
14 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
15};
16pub const API_KEY: i16 = 34;
17pub const MIN_VERSION: i16 = 1;
18pub const MAX_VERSION: i16 = 2;
19pub const FLEXIBLE_MIN: i16 = 2;
20#[inline]
21#[must_use]
22pub fn is_flexible(version: i16) -> bool {
23 version >= FLEXIBLE_MIN
24}
25#[derive(Debug, Clone, PartialEq, Eq, Default)]
26pub struct AlterReplicaLogDirsResponse {
27 pub throttle_time_ms: i32,
28 pub results: Vec<AlterReplicaLogDirTopicResult>,
29 pub unknown_tagged_fields: UnknownTaggedFields,
30}
31impl Encode for AlterReplicaLogDirsResponse {
32 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
33 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
34 return Err(ProtocolError::UnsupportedVersion {
35 api_key: API_KEY,
36 version,
37 });
38 }
39 let flex = is_flexible(version);
40 if version >= 0 {
41 put_i32(buf, self.throttle_time_ms);
42 }
43 if version >= 0 {
44 {
45 crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
46 for it in &self.results {
47 it.encode(buf, version)?;
48 }
49 };
50 }
51 if flex {
52 let tagged = WriteTaggedFields::new();
53 tagged.write(buf, &self.unknown_tagged_fields);
54 }
55 Ok(())
56 }
57 fn encoded_len(&self, version: i16) -> usize {
58 let flex = is_flexible(version);
59 let mut n: usize = 0;
60 if version >= 0 {
61 n += 4;
62 }
63 if version >= 0 {
64 n += {
65 let prefix =
66 crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
67 let body: usize = (self.results)
68 .iter()
69 .map(|it| it.encoded_len(version))
70 .sum();
71 prefix + body
72 };
73 }
74 if flex {
75 let known_pairs: Vec<(u32, usize)> = Vec::new();
76 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
77 }
78 n
79 }
80}
81impl Decode<'_> for AlterReplicaLogDirsResponse {
82 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
83 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
84 return Err(ProtocolError::UnsupportedVersion {
85 api_key: API_KEY,
86 version,
87 });
88 }
89 let flex = is_flexible(version);
90 let mut out = Self::default();
91 if version >= 0 {
92 out.throttle_time_ms = get_i32(buf)?;
93 }
94 if version >= 0 {
95 out.results = {
96 let n = crate::primitives::array::get_array_len(buf, flex)?;
97 let mut v = Vec::with_capacity(n);
98 for _ in 0..n {
99 v.push(AlterReplicaLogDirTopicResult::decode(buf, version)?);
100 }
101 v
102 };
103 }
104 if flex {
105 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
106 }
107 Ok(out)
108 }
109}
110#[cfg(test)]
111impl AlterReplicaLogDirsResponse {
112 #[must_use]
113 pub fn populated(version: i16) -> Self {
114 let mut m = Self::default();
115 if version >= 0 {
116 m.throttle_time_ms = 1i32;
117 }
118 if version >= 0 {
119 m.results = vec![AlterReplicaLogDirTopicResult::populated(version)];
120 }
121 m
122 }
123}
124#[derive(Debug, Clone, PartialEq, Eq, Default)]
125pub struct AlterReplicaLogDirTopicResult {
126 pub topic_name: String,
127 pub partitions: Vec<AlterReplicaLogDirPartitionResult>,
128 pub unknown_tagged_fields: UnknownTaggedFields,
129}
130impl Encode for AlterReplicaLogDirTopicResult {
131 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
132 let flex = version >= 2;
133 if version >= 0 {
134 if flex {
135 let () = put_compact_string(buf, &self.topic_name);
136 } else {
137 let () = put_string(buf, &self.topic_name);
138 }
139 }
140 if version >= 0 {
141 {
142 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
143 for it in &self.partitions {
144 it.encode(buf, version)?;
145 }
146 };
147 }
148 if flex {
149 let tagged = WriteTaggedFields::new();
150 tagged.write(buf, &self.unknown_tagged_fields);
151 }
152 Ok(())
153 }
154 fn encoded_len(&self, version: i16) -> usize {
155 let flex = version >= 2;
156 let mut n: usize = 0;
157 if version >= 0 {
158 n += if flex {
159 compact_string_len(&self.topic_name)
160 } else {
161 string_len(&self.topic_name)
162 };
163 }
164 if version >= 0 {
165 n += {
166 let prefix =
167 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
168 let body: usize = (self.partitions)
169 .iter()
170 .map(|it| it.encoded_len(version))
171 .sum();
172 prefix + body
173 };
174 }
175 if flex {
176 let known_pairs: Vec<(u32, usize)> = Vec::new();
177 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
178 }
179 n
180 }
181}
182impl Decode<'_> for AlterReplicaLogDirTopicResult {
183 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
184 let flex = version >= 2;
185 let mut out = Self::default();
186 if version >= 0 {
187 out.topic_name = if flex {
188 get_compact_string_owned(buf)?
189 } else {
190 get_string_owned(buf)?
191 };
192 }
193 if version >= 0 {
194 out.partitions = {
195 let n = crate::primitives::array::get_array_len(buf, flex)?;
196 let mut v = Vec::with_capacity(n);
197 for _ in 0..n {
198 v.push(AlterReplicaLogDirPartitionResult::decode(buf, version)?);
199 }
200 v
201 };
202 }
203 if flex {
204 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
205 }
206 Ok(out)
207 }
208}
209#[cfg(test)]
210impl AlterReplicaLogDirTopicResult {
211 #[must_use]
212 pub fn populated(version: i16) -> Self {
213 let mut m = Self::default();
214 if version >= 0 {
215 m.topic_name = "x".to_string();
216 }
217 if version >= 0 {
218 m.partitions = vec![AlterReplicaLogDirPartitionResult::populated(version)];
219 }
220 m
221 }
222}
223#[derive(Debug, Clone, PartialEq, Eq, Default)]
224pub struct AlterReplicaLogDirPartitionResult {
225 pub partition_index: i32,
226 pub error_code: i16,
227 pub unknown_tagged_fields: UnknownTaggedFields,
228}
229impl Encode for AlterReplicaLogDirPartitionResult {
230 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
231 let flex = version >= 2;
232 if version >= 0 {
233 put_i32(buf, self.partition_index);
234 }
235 if version >= 0 {
236 put_i16(buf, self.error_code);
237 }
238 if flex {
239 let tagged = WriteTaggedFields::new();
240 tagged.write(buf, &self.unknown_tagged_fields);
241 }
242 Ok(())
243 }
244 fn encoded_len(&self, version: i16) -> usize {
245 let flex = version >= 2;
246 let mut n: usize = 0;
247 if version >= 0 {
248 n += 4;
249 }
250 if version >= 0 {
251 n += 2;
252 }
253 if flex {
254 let known_pairs: Vec<(u32, usize)> = Vec::new();
255 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
256 }
257 n
258 }
259}
260impl Decode<'_> for AlterReplicaLogDirPartitionResult {
261 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
262 let flex = version >= 2;
263 let mut out = Self::default();
264 if version >= 0 {
265 out.partition_index = get_i32(buf)?;
266 }
267 if version >= 0 {
268 out.error_code = get_i16(buf)?;
269 }
270 if flex {
271 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
272 }
273 Ok(out)
274 }
275}
276#[cfg(test)]
277impl AlterReplicaLogDirPartitionResult {
278 #[must_use]
279 pub fn populated(version: i16) -> Self {
280 let mut m = Self::default();
281 if version >= 0 {
282 m.partition_index = 1i32;
283 }
284 if version >= 0 {
285 m.error_code = 1i16;
286 }
287 m
288 }
289}
290#[must_use]
293#[allow(unused_comparisons)]
294pub fn default_json(_version: i16) -> ::serde_json::Value {
295 let mut obj = ::serde_json::Map::new();
296 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
297 obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
298 ::serde_json::Value::Object(obj)
299}