Skip to main content

kacrab_protocol/generated/
consumer_protocol_subscription.rs

1//! Generated from ConsumerProtocolSubscription.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 ConsumerProtocolSubscriptionData {
17    /// The topics that the member wants to consume.
18    pub topics: Vec<KafkaString>,
19    /// User data that will be passed back to the consumer.
20    pub user_data: Option<Bytes>,
21    /// The partitions that the member owns.
22    pub owned_partitions: Vec<TopicPartition>,
23    /// The generation id of the member.
24    pub generation_id: i32,
25    /// The rack id of the member.
26    pub rack_id: Option<KafkaString>,
27    pub _unknown_tagged_fields: Vec<RawTaggedField>,
28}
29impl Default for ConsumerProtocolSubscriptionData {
30    fn default() -> Self {
31        Self {
32            topics: Vec::new(),
33            user_data: None,
34            owned_partitions: Vec::new(),
35            generation_id: -1i32,
36            rack_id: None,
37            _unknown_tagged_fields: Vec::new(),
38        }
39    }
40}
41impl ConsumerProtocolSubscriptionData {
42    pub fn with_topics(mut self, value: Vec<KafkaString>) -> Self {
43        self.topics = value;
44        self
45    }
46    pub fn with_user_data(mut self, value: Option<Bytes>) -> Self {
47        self.user_data = value;
48        self
49    }
50    pub fn with_owned_partitions(mut self, value: Vec<TopicPartition>) -> Self {
51        self.owned_partitions = value;
52        self
53    }
54    pub fn with_generation_id(mut self, value: i32) -> Self {
55        self.generation_id = value;
56        self
57    }
58    pub fn with_rack_id(mut self, value: Option<KafkaString>) -> Self {
59        self.rack_id = value;
60        self
61    }
62    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
63        let topics;
64        let user_data;
65        let mut owned_partitions = Vec::new();
66        let mut generation_id = -1i32;
67        let mut rack_id = None;
68        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
69        topics = {
70            let len = read_array_length(buf)?;
71            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
72            for _ in 0..len {
73                arr.push(read_string(buf)?);
74            }
75            arr
76        };
77        user_data = read_nullable_bytes(buf)?;
78        if version >= 1 {
79            owned_partitions = {
80                let len = read_array_length(buf)?;
81                let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
82                for _ in 0..len {
83                    arr.push(TopicPartition::read(buf, version)?);
84                }
85                arr
86            };
87        }
88        if version >= 2 {
89            generation_id = read_i32(buf)?;
90        }
91        if version >= 3 {
92            rack_id = read_nullable_string(buf)?;
93        }
94        Ok(Self {
95            topics,
96            user_data,
97            owned_partitions,
98            generation_id,
99            rack_id,
100            _unknown_tagged_fields,
101        })
102    }
103    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
104        write_array_length(buf, self.topics.len() as i32);
105        for el in &self.topics {
106            write_string(buf, el)?;
107        }
108        write_nullable_bytes(buf, self.user_data.as_ref().map(|b| b.as_ref()))?;
109        if version >= 1 {
110            write_array_length(buf, self.owned_partitions.len() as i32);
111            for el in &self.owned_partitions {
112                el.write(buf, version)?;
113            }
114        }
115        if version >= 2 {
116            write_i32(buf, self.generation_id);
117        }
118        if version >= 3 {
119            write_nullable_string(buf, self.rack_id.as_ref())?;
120        }
121        Ok(())
122    }
123    pub fn encoded_len(&self, version: i16) -> Result<usize> {
124        let mut len: usize = 0;
125        len += array_length_len();
126        for el in &self.topics {
127            len += string_len(el)?;
128        }
129        len += nullable_bytes_len(self.user_data.as_ref().map(|b| b.as_ref()))?;
130        if version >= 1 {
131            len += array_length_len();
132            for el in &self.owned_partitions {
133                len += el.encoded_len(version)?;
134            }
135        }
136        if version >= 2 {
137            len += 4;
138        }
139        if version >= 3 {
140            len += nullable_string_len(self.rack_id.as_ref())?;
141        }
142        Ok(len)
143    }
144}
145#[derive(Debug, Clone, PartialEq)]
146pub struct TopicPartition {
147    /// The topic name.
148    pub topic: KafkaString,
149    /// The partition ids.
150    pub partitions: Vec<i32>,
151    pub _unknown_tagged_fields: Vec<RawTaggedField>,
152}
153impl Default for TopicPartition {
154    fn default() -> Self {
155        Self {
156            topic: KafkaString::default(),
157            partitions: Vec::new(),
158            _unknown_tagged_fields: Vec::new(),
159        }
160    }
161}
162impl TopicPartition {
163    pub fn with_topic(mut self, value: KafkaString) -> Self {
164        self.topic = value;
165        self
166    }
167    pub fn with_partitions(mut self, value: Vec<i32>) -> Self {
168        self.partitions = value;
169        self
170    }
171    pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
172        let topic;
173        let partitions;
174        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
175        topic = read_string(buf)?;
176        partitions = {
177            let len = read_array_length(buf)?;
178            let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
179            for _ in 0..len {
180                arr.push(read_i32(buf)?);
181            }
182            arr
183        };
184        Ok(Self {
185            topic,
186            partitions,
187            _unknown_tagged_fields,
188        })
189    }
190    pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
191        write_string(buf, &self.topic)?;
192        write_array_length(buf, self.partitions.len() as i32);
193        for el in &self.partitions {
194            write_i32(buf, *el);
195        }
196        Ok(())
197    }
198    pub fn encoded_len(&self, _version: i16) -> Result<usize> {
199        let mut len: usize = 0;
200        len += string_len(&self.topic)?;
201        len += array_length_len();
202        len += self.partitions.len() * 4usize;
203        Ok(len)
204    }
205}