Skip to main content

kacrab_protocol/generated/
consumer_protocol_assignment.rs

1//! Generated from ConsumerProtocolAssignment.json - DO NOT EDIT
2#![allow(
3    missing_docs,
4    clippy::all,
5    clippy::pedantic,
6    clippy::nursery,
7    clippy::arithmetic_side_effects,
8    reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9              hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct ConsumerProtocolAssignmentData {
17    /// The list of topics and partitions assigned to this consumer.
18    pub assigned_partitions: Vec<TopicPartition>,
19    /// User data.
20    pub user_data: Option<Bytes>,
21    pub _unknown_tagged_fields: Vec<RawTaggedField>,
22}
23impl Default for ConsumerProtocolAssignmentData {
24    fn default() -> Self {
25        Self {
26            assigned_partitions: Vec::new(),
27            user_data: None,
28            _unknown_tagged_fields: Vec::new(),
29        }
30    }
31}
32impl ConsumerProtocolAssignmentData {
33    pub fn with_assigned_partitions(mut self, value: Vec<TopicPartition>) -> Self {
34        self.assigned_partitions = value;
35        self
36    }
37    pub fn with_user_data(mut self, value: Option<Bytes>) -> Self {
38        self.user_data = value;
39        self
40    }
41    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
42        let assigned_partitions;
43        let user_data;
44        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
45        assigned_partitions = {
46            let len = read_array_length(buf)?;
47            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
48            for _ in 0..len {
49                arr.push(TopicPartition::read(buf, version)?);
50            }
51            arr
52        };
53        user_data = read_nullable_bytes(buf)?;
54        Ok(Self {
55            assigned_partitions,
56            user_data,
57            _unknown_tagged_fields,
58        })
59    }
60    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
61        write_array_length(buf, self.assigned_partitions.len() as i32);
62        for el in &self.assigned_partitions {
63            el.write(buf, version)?;
64        }
65        write_nullable_bytes(buf, self.user_data.as_ref().map(|b| b.as_ref()))?;
66        Ok(())
67    }
68    pub fn encoded_len(&self, version: i16) -> Result<usize> {
69        let mut len: usize = 0;
70        len += array_length_len();
71        for el in &self.assigned_partitions {
72            len += el.encoded_len(version)?;
73        }
74        len += nullable_bytes_len(self.user_data.as_ref().map(|b| b.as_ref()))?;
75        Ok(len)
76    }
77}
78#[derive(Debug, Clone, PartialEq)]
79pub struct TopicPartition {
80    /// The topic name.
81    pub topic: KafkaString,
82    /// The list of partitions assigned to this consumer.
83    pub partitions: Vec<i32>,
84    pub _unknown_tagged_fields: Vec<RawTaggedField>,
85}
86impl Default for TopicPartition {
87    fn default() -> Self {
88        Self {
89            topic: KafkaString::default(),
90            partitions: Vec::new(),
91            _unknown_tagged_fields: Vec::new(),
92        }
93    }
94}
95impl TopicPartition {
96    pub fn with_topic(mut self, value: KafkaString) -> Self {
97        self.topic = value;
98        self
99    }
100    pub fn with_partitions(mut self, value: Vec<i32>) -> Self {
101        self.partitions = value;
102        self
103    }
104    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
105        let topic;
106        let partitions;
107        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
108        topic = read_string(buf)?;
109        partitions = {
110            let len = read_array_length(buf)?;
111            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
112            for _ in 0..len {
113                arr.push(read_i32(buf)?);
114            }
115            arr
116        };
117        Ok(Self {
118            topic,
119            partitions,
120            _unknown_tagged_fields,
121        })
122    }
123    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
124        write_string(buf, &self.topic)?;
125        write_array_length(buf, self.partitions.len() as i32);
126        for el in &self.partitions {
127            write_i32(buf, *el);
128        }
129        Ok(())
130    }
131    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
132        let mut len: usize = 0;
133        len += string_len(&self.topic)?;
134        len += array_length_len();
135        len += self.partitions.len() * 4usize;
136        Ok(len)
137    }
138}