kafka_protocol/messages/
list_partition_reassignments_request.rs1#![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 ListPartitionReassignmentsRequest {
24 pub timeout_ms: i32,
28
29 pub topics: Option<Vec<ListPartitionReassignmentsTopics>>,
33
34 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
36}
37
38impl ListPartitionReassignmentsRequest {
39 pub fn with_timeout_ms(mut self, value: i32) -> Self {
45 self.timeout_ms = value;
46 self
47 }
48 pub fn with_topics(mut self, value: Option<Vec<ListPartitionReassignmentsTopics>>) -> Self {
54 self.topics = 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 = "client")]
70impl Encodable for ListPartitionReassignmentsRequest {
71 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
72 types::Int32.encode(buf, &self.timeout_ms)?;
73 types::CompactArray(types::Struct { version }).encode(buf, &self.topics)?;
74 let num_tagged_fields = self.unknown_tagged_fields.len();
75 if num_tagged_fields > std::u32::MAX as usize {
76 bail!(
77 "Too many tagged fields to encode ({} fields)",
78 num_tagged_fields
79 );
80 }
81 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
82
83 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
84 Ok(())
85 }
86 fn compute_size(&self, version: i16) -> Result<usize> {
87 let mut total_size = 0;
88 total_size += types::Int32.compute_size(&self.timeout_ms)?;
89 total_size += types::CompactArray(types::Struct { version }).compute_size(&self.topics)?;
90 let num_tagged_fields = self.unknown_tagged_fields.len();
91 if num_tagged_fields > std::u32::MAX as usize {
92 bail!(
93 "Too many tagged fields to encode ({} fields)",
94 num_tagged_fields
95 );
96 }
97 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
98
99 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
100 Ok(total_size)
101 }
102}
103
104#[cfg(feature = "broker")]
105impl Decodable for ListPartitionReassignmentsRequest {
106 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
107 let timeout_ms = types::Int32.decode(buf)?;
108 let topics = types::CompactArray(types::Struct { version }).decode(buf)?;
109 let mut unknown_tagged_fields = BTreeMap::new();
110 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
111 for _ in 0..num_tagged_fields {
112 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
113 let size: u32 = types::UnsignedVarInt.decode(buf)?;
114 let unknown_value = buf.try_get_bytes(size as usize)?;
115 unknown_tagged_fields.insert(tag as i32, unknown_value);
116 }
117 Ok(Self {
118 timeout_ms,
119 topics,
120 unknown_tagged_fields,
121 })
122 }
123}
124
125impl Default for ListPartitionReassignmentsRequest {
126 fn default() -> Self {
127 Self {
128 timeout_ms: 60000,
129 topics: None,
130 unknown_tagged_fields: BTreeMap::new(),
131 }
132 }
133}
134
135impl Message for ListPartitionReassignmentsRequest {
136 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
137 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
138}
139
140#[non_exhaustive]
142#[derive(Debug, Clone, PartialEq)]
143pub struct ListPartitionReassignmentsTopics {
144 pub name: super::TopicName,
148
149 pub partition_indexes: Vec<i32>,
153
154 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
156}
157
158impl ListPartitionReassignmentsTopics {
159 pub fn with_name(mut self, value: super::TopicName) -> Self {
165 self.name = value;
166 self
167 }
168 pub fn with_partition_indexes(mut self, value: Vec<i32>) -> Self {
174 self.partition_indexes = value;
175 self
176 }
177 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
179 self.unknown_tagged_fields = value;
180 self
181 }
182 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
184 self.unknown_tagged_fields.insert(key, value);
185 self
186 }
187}
188
189#[cfg(feature = "client")]
190impl Encodable for ListPartitionReassignmentsTopics {
191 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
192 types::CompactString.encode(buf, &self.name)?;
193 types::CompactArray(types::Int32).encode(buf, &self.partition_indexes)?;
194 let num_tagged_fields = self.unknown_tagged_fields.len();
195 if num_tagged_fields > std::u32::MAX as usize {
196 bail!(
197 "Too many tagged fields to encode ({} fields)",
198 num_tagged_fields
199 );
200 }
201 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
202
203 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
204 Ok(())
205 }
206 fn compute_size(&self, version: i16) -> Result<usize> {
207 let mut total_size = 0;
208 total_size += types::CompactString.compute_size(&self.name)?;
209 total_size += types::CompactArray(types::Int32).compute_size(&self.partition_indexes)?;
210 let num_tagged_fields = self.unknown_tagged_fields.len();
211 if num_tagged_fields > std::u32::MAX as usize {
212 bail!(
213 "Too many tagged fields to encode ({} fields)",
214 num_tagged_fields
215 );
216 }
217 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
218
219 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
220 Ok(total_size)
221 }
222}
223
224#[cfg(feature = "broker")]
225impl Decodable for ListPartitionReassignmentsTopics {
226 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
227 let name = types::CompactString.decode(buf)?;
228 let partition_indexes = types::CompactArray(types::Int32).decode(buf)?;
229 let mut unknown_tagged_fields = BTreeMap::new();
230 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
231 for _ in 0..num_tagged_fields {
232 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
233 let size: u32 = types::UnsignedVarInt.decode(buf)?;
234 let unknown_value = buf.try_get_bytes(size as usize)?;
235 unknown_tagged_fields.insert(tag as i32, unknown_value);
236 }
237 Ok(Self {
238 name,
239 partition_indexes,
240 unknown_tagged_fields,
241 })
242 }
243}
244
245impl Default for ListPartitionReassignmentsTopics {
246 fn default() -> Self {
247 Self {
248 name: Default::default(),
249 partition_indexes: Default::default(),
250 unknown_tagged_fields: BTreeMap::new(),
251 }
252 }
253}
254
255impl Message for ListPartitionReassignmentsTopics {
256 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
257 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
258}
259
260impl HeaderVersion for ListPartitionReassignmentsRequest {
261 fn header_version(version: i16) -> i16 {
262 2
263 }
264}