crabka_protocol/opt/rustwide/workdir/generated/
AlterReplicaLogDirsResponse.owned.rs1use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
4use crate::primitives::string_bytes::{
5 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
6 string_len,
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 = 34;
12pub const MIN_VERSION: i16 = 1;
13pub const MAX_VERSION: i16 = 2;
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 AlterReplicaLogDirsResponse {
21 pub throttle_time_ms: i32,
22 pub results: Vec<AlterReplicaLogDirTopicResult>,
23 pub unknown_tagged_fields: UnknownTaggedFields,
24}
25impl Encode for AlterReplicaLogDirsResponse {
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 AlterReplicaLogDirsResponse {
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(AlterReplicaLogDirTopicResult::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 AlterReplicaLogDirsResponse {
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![AlterReplicaLogDirTopicResult::populated(version)];
114 }
115 m
116 }
117}
118#[derive(Debug, Clone, PartialEq, Eq, Default)]
119pub struct AlterReplicaLogDirTopicResult {
120 pub topic_name: String,
121 pub partitions: Vec<AlterReplicaLogDirPartitionResult>,
122 pub unknown_tagged_fields: UnknownTaggedFields,
123}
124impl Encode for AlterReplicaLogDirTopicResult {
125 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
126 let flex = version >= 2;
127 if version >= 0 {
128 if flex {
129 put_compact_string(buf, &self.topic_name);
130 } else {
131 put_string(buf, &self.topic_name);
132 }
133 }
134 if version >= 0 {
135 {
136 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
137 for it in &self.partitions {
138 it.encode(buf, version)?;
139 }
140 }
141 }
142 if flex {
143 let tagged = WriteTaggedFields::new();
144 tagged.write(buf, &self.unknown_tagged_fields);
145 }
146 Ok(())
147 }
148 fn encoded_len(&self, version: i16) -> usize {
149 let flex = version >= 2;
150 let mut n: usize = 0;
151 if version >= 0 {
152 n += if flex {
153 compact_string_len(&self.topic_name)
154 } else {
155 string_len(&self.topic_name)
156 };
157 }
158 if version >= 0 {
159 n += {
160 let prefix =
161 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
162 let body: usize = (self.partitions)
163 .iter()
164 .map(|it| it.encoded_len(version))
165 .sum();
166 prefix + body
167 };
168 }
169 if flex {
170 let known_pairs: Vec<(u32, usize)> = Vec::new();
171 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
172 }
173 n
174 }
175}
176impl Decode<'_> for AlterReplicaLogDirTopicResult {
177 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
178 let flex = version >= 2;
179 let mut out = Self::default();
180 if version >= 0 {
181 out.topic_name = if flex {
182 get_compact_string_owned(buf)?
183 } else {
184 get_string_owned(buf)?
185 };
186 }
187 if version >= 0 {
188 out.partitions = {
189 let n = crate::primitives::array::get_array_len(buf, flex)?;
190 let mut v = Vec::with_capacity(n);
191 for _ in 0..n {
192 v.push(AlterReplicaLogDirPartitionResult::decode(buf, version)?);
193 }
194 v
195 };
196 }
197 if flex {
198 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
199 }
200 Ok(out)
201 }
202}
203#[cfg(test)]
204impl AlterReplicaLogDirTopicResult {
205 #[must_use]
206 pub fn populated(version: i16) -> Self {
207 let mut m = Self::default();
208 if version >= 0 {
209 m.topic_name = "x".to_string();
210 }
211 if version >= 0 {
212 m.partitions = vec![AlterReplicaLogDirPartitionResult::populated(version)];
213 }
214 m
215 }
216}
217#[derive(Debug, Clone, PartialEq, Eq, Default)]
218pub struct AlterReplicaLogDirPartitionResult {
219 pub partition_index: i32,
220 pub error_code: i16,
221 pub unknown_tagged_fields: UnknownTaggedFields,
222}
223impl Encode for AlterReplicaLogDirPartitionResult {
224 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
225 let flex = version >= 2;
226 if version >= 0 {
227 put_i32(buf, self.partition_index);
228 }
229 if version >= 0 {
230 put_i16(buf, self.error_code);
231 }
232 if flex {
233 let tagged = WriteTaggedFields::new();
234 tagged.write(buf, &self.unknown_tagged_fields);
235 }
236 Ok(())
237 }
238 fn encoded_len(&self, version: i16) -> usize {
239 let flex = version >= 2;
240 let mut n: usize = 0;
241 if version >= 0 {
242 n += 4;
243 }
244 if version >= 0 {
245 n += 2;
246 }
247 if flex {
248 let known_pairs: Vec<(u32, usize)> = Vec::new();
249 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
250 }
251 n
252 }
253}
254impl Decode<'_> for AlterReplicaLogDirPartitionResult {
255 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
256 let flex = version >= 2;
257 let mut out = Self::default();
258 if version >= 0 {
259 out.partition_index = get_i32(buf)?;
260 }
261 if version >= 0 {
262 out.error_code = get_i16(buf)?;
263 }
264 if flex {
265 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
266 }
267 Ok(out)
268 }
269}
270#[cfg(test)]
271impl AlterReplicaLogDirPartitionResult {
272 #[must_use]
273 pub fn populated(version: i16) -> Self {
274 let mut m = Self::default();
275 if version >= 0 {
276 m.partition_index = 1i32;
277 }
278 if version >= 0 {
279 m.error_code = 1i16;
280 }
281 m
282 }
283}
284#[must_use]
287#[allow(unused_comparisons)]
288pub fn default_json(version: i16) -> ::serde_json::Value {
289 let mut obj = ::serde_json::Map::new();
290 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
291 obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
292 ::serde_json::Value::Object(obj)
293}