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 PartitionResult {
24 pub partition: i32,
28
29 pub error_code: i16,
33
34 pub error_message: Option<StrBytes>,
38
39 pub state_epoch: i32,
43
44 pub leader_epoch: i32,
48
49 pub start_offset: i64,
53
54 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
56}
57
58impl PartitionResult {
59 pub fn with_partition(mut self, value: i32) -> Self {
65 self.partition = value;
66 self
67 }
68 pub fn with_error_code(mut self, value: i16) -> Self {
74 self.error_code = value;
75 self
76 }
77 pub fn with_error_message(mut self, value: Option<StrBytes>) -> Self {
83 self.error_message = value;
84 self
85 }
86 pub fn with_state_epoch(mut self, value: i32) -> Self {
92 self.state_epoch = value;
93 self
94 }
95 pub fn with_leader_epoch(mut self, value: i32) -> Self {
101 self.leader_epoch = value;
102 self
103 }
104 pub fn with_start_offset(mut self, value: i64) -> Self {
110 self.start_offset = value;
111 self
112 }
113 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
115 self.unknown_tagged_fields = value;
116 self
117 }
118 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
120 self.unknown_tagged_fields.insert(key, value);
121 self
122 }
123}
124
125#[cfg(feature = "broker")]
126impl Encodable for PartitionResult {
127 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
128 if version != 0 {
129 bail!("specified version not supported by this message type");
130 }
131 types::Int32.encode(buf, &self.partition)?;
132 types::Int16.encode(buf, &self.error_code)?;
133 types::CompactString.encode(buf, &self.error_message)?;
134 types::Int32.encode(buf, &self.state_epoch)?;
135 types::Int32.encode(buf, &self.leader_epoch)?;
136 types::Int64.encode(buf, &self.start_offset)?;
137 let num_tagged_fields = self.unknown_tagged_fields.len();
138 if num_tagged_fields > std::u32::MAX as usize {
139 bail!(
140 "Too many tagged fields to encode ({} fields)",
141 num_tagged_fields
142 );
143 }
144 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
145
146 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
147 Ok(())
148 }
149 fn compute_size(&self, version: i16) -> Result<usize> {
150 let mut total_size = 0;
151 total_size += types::Int32.compute_size(&self.partition)?;
152 total_size += types::Int16.compute_size(&self.error_code)?;
153 total_size += types::CompactString.compute_size(&self.error_message)?;
154 total_size += types::Int32.compute_size(&self.state_epoch)?;
155 total_size += types::Int32.compute_size(&self.leader_epoch)?;
156 total_size += types::Int64.compute_size(&self.start_offset)?;
157 let num_tagged_fields = self.unknown_tagged_fields.len();
158 if num_tagged_fields > std::u32::MAX as usize {
159 bail!(
160 "Too many tagged fields to encode ({} fields)",
161 num_tagged_fields
162 );
163 }
164 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
165
166 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
167 Ok(total_size)
168 }
169}
170
171#[cfg(feature = "client")]
172impl Decodable for PartitionResult {
173 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
174 if version != 0 {
175 bail!("specified version not supported by this message type");
176 }
177 let partition = types::Int32.decode(buf)?;
178 let error_code = types::Int16.decode(buf)?;
179 let error_message = types::CompactString.decode(buf)?;
180 let state_epoch = types::Int32.decode(buf)?;
181 let leader_epoch = types::Int32.decode(buf)?;
182 let start_offset = types::Int64.decode(buf)?;
183 let mut unknown_tagged_fields = BTreeMap::new();
184 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
185 for _ in 0..num_tagged_fields {
186 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
187 let size: u32 = types::UnsignedVarInt.decode(buf)?;
188 let unknown_value = buf.try_get_bytes(size as usize)?;
189 unknown_tagged_fields.insert(tag as i32, unknown_value);
190 }
191 Ok(Self {
192 partition,
193 error_code,
194 error_message,
195 state_epoch,
196 leader_epoch,
197 start_offset,
198 unknown_tagged_fields,
199 })
200 }
201}
202
203impl Default for PartitionResult {
204 fn default() -> Self {
205 Self {
206 partition: 0,
207 error_code: 0,
208 error_message: None,
209 state_epoch: 0,
210 leader_epoch: 0,
211 start_offset: 0,
212 unknown_tagged_fields: BTreeMap::new(),
213 }
214 }
215}
216
217impl Message for PartitionResult {
218 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
219 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
220}
221
222#[non_exhaustive]
224#[derive(Debug, Clone, PartialEq)]
225pub struct ReadShareGroupStateSummaryResponse {
226 pub results: Vec<ReadStateSummaryResult>,
230
231 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
233}
234
235impl ReadShareGroupStateSummaryResponse {
236 pub fn with_results(mut self, value: Vec<ReadStateSummaryResult>) -> Self {
242 self.results = value;
243 self
244 }
245 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
247 self.unknown_tagged_fields = value;
248 self
249 }
250 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
252 self.unknown_tagged_fields.insert(key, value);
253 self
254 }
255}
256
257#[cfg(feature = "broker")]
258impl Encodable for ReadShareGroupStateSummaryResponse {
259 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
260 if version != 0 {
261 bail!("specified version not supported by this message type");
262 }
263 types::CompactArray(types::Struct { version }).encode(buf, &self.results)?;
264 let num_tagged_fields = self.unknown_tagged_fields.len();
265 if num_tagged_fields > std::u32::MAX as usize {
266 bail!(
267 "Too many tagged fields to encode ({} fields)",
268 num_tagged_fields
269 );
270 }
271 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
272
273 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
274 Ok(())
275 }
276 fn compute_size(&self, version: i16) -> Result<usize> {
277 let mut total_size = 0;
278 total_size += types::CompactArray(types::Struct { version }).compute_size(&self.results)?;
279 let num_tagged_fields = self.unknown_tagged_fields.len();
280 if num_tagged_fields > std::u32::MAX as usize {
281 bail!(
282 "Too many tagged fields to encode ({} fields)",
283 num_tagged_fields
284 );
285 }
286 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
287
288 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
289 Ok(total_size)
290 }
291}
292
293#[cfg(feature = "client")]
294impl Decodable for ReadShareGroupStateSummaryResponse {
295 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
296 if version != 0 {
297 bail!("specified version not supported by this message type");
298 }
299 let results = types::CompactArray(types::Struct { version }).decode(buf)?;
300 let mut unknown_tagged_fields = BTreeMap::new();
301 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
302 for _ in 0..num_tagged_fields {
303 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
304 let size: u32 = types::UnsignedVarInt.decode(buf)?;
305 let unknown_value = buf.try_get_bytes(size as usize)?;
306 unknown_tagged_fields.insert(tag as i32, unknown_value);
307 }
308 Ok(Self {
309 results,
310 unknown_tagged_fields,
311 })
312 }
313}
314
315impl Default for ReadShareGroupStateSummaryResponse {
316 fn default() -> Self {
317 Self {
318 results: Default::default(),
319 unknown_tagged_fields: BTreeMap::new(),
320 }
321 }
322}
323
324impl Message for ReadShareGroupStateSummaryResponse {
325 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
326 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
327}
328
329#[non_exhaustive]
331#[derive(Debug, Clone, PartialEq)]
332pub struct ReadStateSummaryResult {
333 pub topic_id: Uuid,
337
338 pub partitions: Vec<PartitionResult>,
342
343 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
345}
346
347impl ReadStateSummaryResult {
348 pub fn with_topic_id(mut self, value: Uuid) -> Self {
354 self.topic_id = value;
355 self
356 }
357 pub fn with_partitions(mut self, value: Vec<PartitionResult>) -> Self {
363 self.partitions = value;
364 self
365 }
366 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
368 self.unknown_tagged_fields = value;
369 self
370 }
371 pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
373 self.unknown_tagged_fields.insert(key, value);
374 self
375 }
376}
377
378#[cfg(feature = "broker")]
379impl Encodable for ReadStateSummaryResult {
380 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
381 if version != 0 {
382 bail!("specified version not supported by this message type");
383 }
384 types::Uuid.encode(buf, &self.topic_id)?;
385 types::CompactArray(types::Struct { version }).encode(buf, &self.partitions)?;
386 let num_tagged_fields = self.unknown_tagged_fields.len();
387 if num_tagged_fields > std::u32::MAX as usize {
388 bail!(
389 "Too many tagged fields to encode ({} fields)",
390 num_tagged_fields
391 );
392 }
393 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
394
395 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
396 Ok(())
397 }
398 fn compute_size(&self, version: i16) -> Result<usize> {
399 let mut total_size = 0;
400 total_size += types::Uuid.compute_size(&self.topic_id)?;
401 total_size +=
402 types::CompactArray(types::Struct { version }).compute_size(&self.partitions)?;
403 let num_tagged_fields = self.unknown_tagged_fields.len();
404 if num_tagged_fields > std::u32::MAX as usize {
405 bail!(
406 "Too many tagged fields to encode ({} fields)",
407 num_tagged_fields
408 );
409 }
410 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
411
412 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
413 Ok(total_size)
414 }
415}
416
417#[cfg(feature = "client")]
418impl Decodable for ReadStateSummaryResult {
419 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
420 if version != 0 {
421 bail!("specified version not supported by this message type");
422 }
423 let topic_id = types::Uuid.decode(buf)?;
424 let partitions = types::CompactArray(types::Struct { version }).decode(buf)?;
425 let mut unknown_tagged_fields = BTreeMap::new();
426 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
427 for _ in 0..num_tagged_fields {
428 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
429 let size: u32 = types::UnsignedVarInt.decode(buf)?;
430 let unknown_value = buf.try_get_bytes(size as usize)?;
431 unknown_tagged_fields.insert(tag as i32, unknown_value);
432 }
433 Ok(Self {
434 topic_id,
435 partitions,
436 unknown_tagged_fields,
437 })
438 }
439}
440
441impl Default for ReadStateSummaryResult {
442 fn default() -> Self {
443 Self {
444 topic_id: Uuid::nil(),
445 partitions: Default::default(),
446 unknown_tagged_fields: BTreeMap::new(),
447 }
448 }
449}
450
451impl Message for ReadStateSummaryResult {
452 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
453 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
454}
455
456impl HeaderVersion for ReadShareGroupStateSummaryResponse {
457 fn header_version(version: i16) -> i16 {
458 1
459 }
460}