kafka_protocol/messages/
consumer_protocol_assignment.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 ConsumerProtocolAssignment {
24 pub assigned_partitions: Vec<TopicPartition>,
28
29 pub user_data: Option<Bytes>,
33}
34
35impl ConsumerProtocolAssignment {
36 pub fn with_assigned_partitions(mut self, value: Vec<TopicPartition>) -> Self {
42 self.assigned_partitions = value;
43 self
44 }
45 pub fn with_user_data(mut self, value: Option<Bytes>) -> Self {
51 self.user_data = value;
52 self
53 }
54}
55
56impl Encodable for ConsumerProtocolAssignment {
57 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
58 if version < 0 || version > 3 {
59 bail!("specified version not supported by this message type");
60 }
61 types::Array(types::Struct { version }).encode(buf, &self.assigned_partitions)?;
62 types::Bytes.encode(buf, &self.user_data)?;
63
64 Ok(())
65 }
66 fn compute_size(&self, version: i16) -> Result<usize> {
67 let mut total_size = 0;
68 total_size +=
69 types::Array(types::Struct { version }).compute_size(&self.assigned_partitions)?;
70 total_size += types::Bytes.compute_size(&self.user_data)?;
71
72 Ok(total_size)
73 }
74}
75
76impl Decodable for ConsumerProtocolAssignment {
77 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
78 if version < 0 || version > 3 {
79 bail!("specified version not supported by this message type");
80 }
81 let assigned_partitions = types::Array(types::Struct { version }).decode(buf)?;
82 let user_data = types::Bytes.decode(buf)?;
83 Ok(Self {
84 assigned_partitions,
85 user_data,
86 })
87 }
88}
89
90impl Default for ConsumerProtocolAssignment {
91 fn default() -> Self {
92 Self {
93 assigned_partitions: Default::default(),
94 user_data: None,
95 }
96 }
97}
98
99impl Message for ConsumerProtocolAssignment {
100 const VERSIONS: VersionRange = VersionRange { min: 0, max: 3 };
101 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
102}
103
104#[non_exhaustive]
106#[derive(Debug, Clone, PartialEq)]
107pub struct TopicPartition {
108 pub topic: super::TopicName,
112
113 pub partitions: Vec<i32>,
117}
118
119impl TopicPartition {
120 pub fn with_topic(mut self, value: super::TopicName) -> Self {
126 self.topic = value;
127 self
128 }
129 pub fn with_partitions(mut self, value: Vec<i32>) -> Self {
135 self.partitions = value;
136 self
137 }
138}
139
140impl Encodable for TopicPartition {
141 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
142 if version < 0 || version > 3 {
143 bail!("specified version not supported by this message type");
144 }
145 types::String.encode(buf, &self.topic)?;
146 types::Array(types::Int32).encode(buf, &self.partitions)?;
147
148 Ok(())
149 }
150 fn compute_size(&self, version: i16) -> Result<usize> {
151 let mut total_size = 0;
152 total_size += types::String.compute_size(&self.topic)?;
153 total_size += types::Array(types::Int32).compute_size(&self.partitions)?;
154
155 Ok(total_size)
156 }
157}
158
159impl Decodable for TopicPartition {
160 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
161 if version < 0 || version > 3 {
162 bail!("specified version not supported by this message type");
163 }
164 let topic = types::String.decode(buf)?;
165 let partitions = types::Array(types::Int32).decode(buf)?;
166 Ok(Self { topic, partitions })
167 }
168}
169
170impl Default for TopicPartition {
171 fn default() -> Self {
172 Self {
173 topic: Default::default(),
174 partitions: Default::default(),
175 }
176 }
177}
178
179impl Message for TopicPartition {
180 const VERSIONS: VersionRange = VersionRange { min: 0, max: 3 };
181 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
182}