kafka_protocol/messages/
consumer_protocol_assignment.rs

1//! ConsumerProtocolAssignment
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/ConsumerProtocolAssignment.json).
4// WARNING: the items of this module are generated and should not be edited directly
5#![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/// Valid versions: 0-3
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct ConsumerProtocolAssignment {
24    ///
25    ///
26    /// Supported API versions: 0-3
27    pub assigned_partitions: Vec<TopicPartition>,
28
29    ///
30    ///
31    /// Supported API versions: 0-3
32    pub user_data: Option<Bytes>,
33}
34
35impl ConsumerProtocolAssignment {
36    /// Sets `assigned_partitions` to the passed value.
37    ///
38    ///
39    ///
40    /// Supported API versions: 0-3
41    pub fn with_assigned_partitions(mut self, value: Vec<TopicPartition>) -> Self {
42        self.assigned_partitions = value;
43        self
44    }
45    /// Sets `user_data` to the passed value.
46    ///
47    ///
48    ///
49    /// Supported API versions: 0-3
50    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        types::Array(types::Struct { version }).encode(buf, &self.assigned_partitions)?;
59        types::Bytes.encode(buf, &self.user_data)?;
60
61        Ok(())
62    }
63    fn compute_size(&self, version: i16) -> Result<usize> {
64        let mut total_size = 0;
65        total_size +=
66            types::Array(types::Struct { version }).compute_size(&self.assigned_partitions)?;
67        total_size += types::Bytes.compute_size(&self.user_data)?;
68
69        Ok(total_size)
70    }
71}
72
73impl Decodable for ConsumerProtocolAssignment {
74    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
75        let assigned_partitions = types::Array(types::Struct { version }).decode(buf)?;
76        let user_data = types::Bytes.decode(buf)?;
77        Ok(Self {
78            assigned_partitions,
79            user_data,
80        })
81    }
82}
83
84impl Default for ConsumerProtocolAssignment {
85    fn default() -> Self {
86        Self {
87            assigned_partitions: Default::default(),
88            user_data: None,
89        }
90    }
91}
92
93impl Message for ConsumerProtocolAssignment {
94    const VERSIONS: VersionRange = VersionRange { min: 0, max: 3 };
95    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
96}
97
98/// Valid versions: 0-3
99#[non_exhaustive]
100#[derive(Debug, Clone, PartialEq)]
101pub struct TopicPartition {
102    ///
103    ///
104    /// Supported API versions: 0-3
105    pub topic: super::TopicName,
106
107    ///
108    ///
109    /// Supported API versions: 0-3
110    pub partitions: Vec<i32>,
111}
112
113impl TopicPartition {
114    /// Sets `topic` to the passed value.
115    ///
116    ///
117    ///
118    /// Supported API versions: 0-3
119    pub fn with_topic(mut self, value: super::TopicName) -> Self {
120        self.topic = value;
121        self
122    }
123    /// Sets `partitions` to the passed value.
124    ///
125    ///
126    ///
127    /// Supported API versions: 0-3
128    pub fn with_partitions(mut self, value: Vec<i32>) -> Self {
129        self.partitions = value;
130        self
131    }
132}
133
134impl Encodable for TopicPartition {
135    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
136        types::String.encode(buf, &self.topic)?;
137        types::Array(types::Int32).encode(buf, &self.partitions)?;
138
139        Ok(())
140    }
141    fn compute_size(&self, version: i16) -> Result<usize> {
142        let mut total_size = 0;
143        total_size += types::String.compute_size(&self.topic)?;
144        total_size += types::Array(types::Int32).compute_size(&self.partitions)?;
145
146        Ok(total_size)
147    }
148}
149
150impl Decodable for TopicPartition {
151    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
152        let topic = types::String.decode(buf)?;
153        let partitions = types::Array(types::Int32).decode(buf)?;
154        Ok(Self { topic, partitions })
155    }
156}
157
158impl Default for TopicPartition {
159    fn default() -> Self {
160        Self {
161            topic: Default::default(),
162            partitions: Default::default(),
163        }
164    }
165}
166
167impl Message for TopicPartition {
168    const VERSIONS: VersionRange = VersionRange { min: 0, max: 3 };
169    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
170}