1#![allow(unused)]
6
7use std::borrow::Borrow;
8use std::collections::BTreeMap;
9
10use anyhow::{bail, Result};
11use bytes::Bytes;
12use uuid::Uuid;
13
14use crate::protocol::{
15 buf::{ByteBuf, ByteBufMut},
16 compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder,
17 Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange,
18};
19
20#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct AlterReplicaLogDirPartitionResult {
24 pub partition_index: i32,
28
29 pub error_code: i16,
33
34 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
36}
37
38impl AlterReplicaLogDirPartitionResult {
39 pub fn with_partition_index(mut self, value: i32) -> Self {
45 self.partition_index = value;
46 self
47 }
48 pub fn with_error_code(mut self, value: i16) -> Self {
54 self.error_code = value;
55 self
56 }
57 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
59 self.unknown_tagged_fields = value;
60 self
61 }
62 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
64 self.unknown_tagged_fields.insert(key, value);
65 self
66 }
67}
68
69#[cfg(feature = "broker")]
70impl Encodable for AlterReplicaLogDirPartitionResult {
71 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
72 if version < 1 || version > 2 {
73 bail!("specified version not supported by this message type");
74 }
75 types::Int32.encode(buf, &self.partition_index)?;
76 types::Int16.encode(buf, &self.error_code)?;
77 if version >= 2 {
78 let num_tagged_fields = self.unknown_tagged_fields.len();
79 if num_tagged_fields > std::u32::MAX as usize {
80 bail!(
81 "Too many tagged fields to encode ({} fields)",
82 num_tagged_fields
83 );
84 }
85 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
86
87 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
88 }
89 Ok(())
90 }
91 fn compute_size(&self, version: i16) -> Result<usize> {
92 let mut total_size = 0;
93 total_size += types::Int32.compute_size(&self.partition_index)?;
94 total_size += types::Int16.compute_size(&self.error_code)?;
95 if version >= 2 {
96 let num_tagged_fields = self.unknown_tagged_fields.len();
97 if num_tagged_fields > std::u32::MAX as usize {
98 bail!(
99 "Too many tagged fields to encode ({} fields)",
100 num_tagged_fields
101 );
102 }
103 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
104
105 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
106 }
107 Ok(total_size)
108 }
109}
110
111#[cfg(feature = "client")]
112impl Decodable for AlterReplicaLogDirPartitionResult {
113 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
114 if version < 1 || version > 2 {
115 bail!("specified version not supported by this message type");
116 }
117 let partition_index = types::Int32.decode(buf)?;
118 let error_code = types::Int16.decode(buf)?;
119 let mut unknown_tagged_fields = BTreeMap::new();
120 if version >= 2 {
121 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
122 for _ in 0..num_tagged_fields {
123 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
124 let size: u32 = types::UnsignedVarInt.decode(buf)?;
125 let unknown_value = buf.try_get_bytes(size as usize)?;
126 unknown_tagged_fields.insert(tag as i32, unknown_value);
127 }
128 }
129 Ok(Self {
130 partition_index,
131 error_code,
132 unknown_tagged_fields,
133 })
134 }
135}
136
137impl Default for AlterReplicaLogDirPartitionResult {
138 fn default() -> Self {
139 Self {
140 partition_index: 0,
141 error_code: 0,
142 unknown_tagged_fields: BTreeMap::new(),
143 }
144 }
145}
146
147impl Message for AlterReplicaLogDirPartitionResult {
148 const VERSIONS: VersionRange = VersionRange { min: 1, max: 2 };
149 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
150}
151
152#[non_exhaustive]
154#[derive(Debug, Clone, PartialEq)]
155pub struct AlterReplicaLogDirTopicResult {
156 pub topic_name: super::TopicName,
160
161 pub partitions: Vec<AlterReplicaLogDirPartitionResult>,
165
166 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
168}
169
170impl AlterReplicaLogDirTopicResult {
171 pub fn with_topic_name(mut self, value: super::TopicName) -> Self {
177 self.topic_name = value;
178 self
179 }
180 pub fn with_partitions(mut self, value: Vec<AlterReplicaLogDirPartitionResult>) -> Self {
186 self.partitions = value;
187 self
188 }
189 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
191 self.unknown_tagged_fields = value;
192 self
193 }
194 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
196 self.unknown_tagged_fields.insert(key, value);
197 self
198 }
199}
200
201#[cfg(feature = "broker")]
202impl Encodable for AlterReplicaLogDirTopicResult {
203 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
204 if version < 1 || version > 2 {
205 bail!("specified version not supported by this message type");
206 }
207 if version >= 2 {
208 types::CompactString.encode(buf, &self.topic_name)?;
209 } else {
210 types::String.encode(buf, &self.topic_name)?;
211 }
212 if version >= 2 {
213 types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?;
214 } else {
215 types::Array(types::Struct { version }).encode(buf, &self.partitions)?;
216 }
217 if version >= 2 {
218 let num_tagged_fields = self.unknown_tagged_fields.len();
219 if num_tagged_fields > std::u32::MAX as usize {
220 bail!(
221 "Too many tagged fields to encode ({} fields)",
222 num_tagged_fields
223 );
224 }
225 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
226
227 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
228 }
229 Ok(())
230 }
231 fn compute_size(&self, version: i16) -> Result<usize> {
232 let mut total_size = 0;
233 if version >= 2 {
234 total_size += types::CompactString.compute_size(&self.topic_name)?;
235 } else {
236 total_size += types::String.compute_size(&self.topic_name)?;
237 }
238 if version >= 2 {
239 total_size +=
240 types::CompactArray(types::Struct { version }).compute_size(&self.partitions)?;
241 } else {
242 total_size += types::Array(types::Struct { version }).compute_size(&self.partitions)?;
243 }
244 if version >= 2 {
245 let num_tagged_fields = self.unknown_tagged_fields.len();
246 if num_tagged_fields > std::u32::MAX as usize {
247 bail!(
248 "Too many tagged fields to encode ({} fields)",
249 num_tagged_fields
250 );
251 }
252 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
253
254 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
255 }
256 Ok(total_size)
257 }
258}
259
260#[cfg(feature = "client")]
261impl Decodable for AlterReplicaLogDirTopicResult {
262 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
263 if version < 1 || version > 2 {
264 bail!("specified version not supported by this message type");
265 }
266 let topic_name = if version >= 2 {
267 types::CompactString.decode(buf)?
268 } else {
269 types::String.decode(buf)?
270 };
271 let partitions = if version >= 2 {
272 types::CompactArray(types::Struct { version }).decode(buf)?
273 } else {
274 types::Array(types::Struct { version }).decode(buf)?
275 };
276 let mut unknown_tagged_fields = BTreeMap::new();
277 if version >= 2 {
278 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
279 for _ in 0..num_tagged_fields {
280 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
281 let size: u32 = types::UnsignedVarInt.decode(buf)?;
282 let unknown_value = buf.try_get_bytes(size as usize)?;
283 unknown_tagged_fields.insert(tag as i32, unknown_value);
284 }
285 }
286 Ok(Self {
287 topic_name,
288 partitions,
289 unknown_tagged_fields,
290 })
291 }
292}
293
294impl Default for AlterReplicaLogDirTopicResult {
295 fn default() -> Self {
296 Self {
297 topic_name: Default::default(),
298 partitions: Default::default(),
299 unknown_tagged_fields: BTreeMap::new(),
300 }
301 }
302}
303
304impl Message for AlterReplicaLogDirTopicResult {
305 const VERSIONS: VersionRange = VersionRange { min: 1, max: 2 };
306 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
307}
308
309#[non_exhaustive]
311#[derive(Debug, Clone, PartialEq)]
312pub struct AlterReplicaLogDirsResponse {
313 pub throttle_time_ms: i32,
317
318 pub results: Vec<AlterReplicaLogDirTopicResult>,
322
323 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
325}
326
327impl AlterReplicaLogDirsResponse {
328 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
334 self.throttle_time_ms = value;
335 self
336 }
337 pub fn with_results(mut self, value: Vec<AlterReplicaLogDirTopicResult>) -> Self {
343 self.results = value;
344 self
345 }
346 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
348 self.unknown_tagged_fields = value;
349 self
350 }
351 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
353 self.unknown_tagged_fields.insert(key, value);
354 self
355 }
356}
357
358#[cfg(feature = "broker")]
359impl Encodable for AlterReplicaLogDirsResponse {
360 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
361 if version < 1 || version > 2 {
362 bail!("specified version not supported by this message type");
363 }
364 types::Int32.encode(buf, &self.throttle_time_ms)?;
365 if version >= 2 {
366 types::CompactArray(types::Struct { version }).encode(buf, &self.results)?;
367 } else {
368 types::Array(types::Struct { version }).encode(buf, &self.results)?;
369 }
370 if version >= 2 {
371 let num_tagged_fields = self.unknown_tagged_fields.len();
372 if num_tagged_fields > std::u32::MAX as usize {
373 bail!(
374 "Too many tagged fields to encode ({} fields)",
375 num_tagged_fields
376 );
377 }
378 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
379
380 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
381 }
382 Ok(())
383 }
384 fn compute_size(&self, version: i16) -> Result<usize> {
385 let mut total_size = 0;
386 total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
387 if version >= 2 {
388 total_size +=
389 types::CompactArray(types::Struct { version }).compute_size(&self.results)?;
390 } else {
391 total_size += types::Array(types::Struct { version }).compute_size(&self.results)?;
392 }
393 if version >= 2 {
394 let num_tagged_fields = self.unknown_tagged_fields.len();
395 if num_tagged_fields > std::u32::MAX as usize {
396 bail!(
397 "Too many tagged fields to encode ({} fields)",
398 num_tagged_fields
399 );
400 }
401 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
402
403 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
404 }
405 Ok(total_size)
406 }
407}
408
409#[cfg(feature = "client")]
410impl Decodable for AlterReplicaLogDirsResponse {
411 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
412 if version < 1 || version > 2 {
413 bail!("specified version not supported by this message type");
414 }
415 let throttle_time_ms = types::Int32.decode(buf)?;
416 let results = if version >= 2 {
417 types::CompactArray(types::Struct { version }).decode(buf)?
418 } else {
419 types::Array(types::Struct { version }).decode(buf)?
420 };
421 let mut unknown_tagged_fields = BTreeMap::new();
422 if version >= 2 {
423 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
424 for _ in 0..num_tagged_fields {
425 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
426 let size: u32 = types::UnsignedVarInt.decode(buf)?;
427 let unknown_value = buf.try_get_bytes(size as usize)?;
428 unknown_tagged_fields.insert(tag as i32, unknown_value);
429 }
430 }
431 Ok(Self {
432 throttle_time_ms,
433 results,
434 unknown_tagged_fields,
435 })
436 }
437}
438
439impl Default for AlterReplicaLogDirsResponse {
440 fn default() -> Self {
441 Self {
442 throttle_time_ms: 0,
443 results: Default::default(),
444 unknown_tagged_fields: BTreeMap::new(),
445 }
446 }
447}
448
449impl Message for AlterReplicaLogDirsResponse {
450 const VERSIONS: VersionRange = VersionRange { min: 1, max: 2 };
451 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
452}
453
454impl HeaderVersion for AlterReplicaLogDirsResponse {
455 fn header_version(version: i16) -> i16 {
456 if version >= 2 {
457 1
458 } else {
459 0
460 }
461 }
462}