kafka_wire_protocol/schema/alter_partition_request/
v2.rs

1// This file was generated. Do not edit.
2
3use std::io::{Read, Result, Write};
4
5use serde::{Deserialize, Serialize};
6use uuid::Uuid;
7#[cfg(test)] use proptest_derive::Arbitrary;
8
9use crate::arrays::{read_array, write_array};
10use crate::markers::{ApiMessage, Request};
11use crate::readable_writable::{Readable, Writable};
12use crate::tagged_fields::{RawTaggedField, read_tagged_fields, write_tagged_fields};
13#[cfg(test)] use crate::test_utils::proptest_strategies;
14
15/// AlterPartitionRequest, version 2.
16#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
17#[cfg_attr(test, derive(Arbitrary))]
18pub struct AlterPartitionRequest {
19    /// The ID of the requesting broker.
20    pub broker_id: i32,
21    /// The epoch of the requesting broker.
22    pub broker_epoch: i64,
23    /// The topics to alter ISRs for.
24    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
25    pub topics: Vec<TopicData>,
26    /// Unknown tagged fields.
27    #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
28    pub _unknown_tagged_fields: Vec<RawTaggedField>,
29}
30
31impl ApiMessage for AlterPartitionRequest {
32    fn api_key(&self) -> i16 {
33        56
34    }
35    
36    fn version(&self) -> i16 {
37        2
38    }
39}
40
41impl Request for AlterPartitionRequest { }
42
43impl Default for AlterPartitionRequest {
44    fn default() -> Self {
45        AlterPartitionRequest {
46            broker_id: 0_i32,
47            broker_epoch: -1_i64,
48            topics: Vec::<TopicData>::new(),
49            _unknown_tagged_fields: Vec::new(),
50        }
51    }
52}
53
54impl AlterPartitionRequest {
55    pub fn new(broker_id: i32, broker_epoch: i64, topics: Vec<TopicData>) -> Self {
56        Self {
57            broker_id,
58            broker_epoch,
59            topics,
60            _unknown_tagged_fields: vec![],
61        }
62    }
63}
64
65#[cfg(test)]
66mod tests_alter_partition_request_new_and_default {
67    use super::*;
68    
69    #[test]
70    fn test() {
71        let d = AlterPartitionRequest::new(
72            0_i32,
73            -1_i64,
74            Vec::<TopicData>::new(),
75        );
76        assert_eq!(d, AlterPartitionRequest::default());
77    }
78}
79
80impl Readable for AlterPartitionRequest {
81    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
82        let broker_id = i32::read(input)?;
83        let broker_epoch = i64::read(input)?;
84        let topics = read_array::<TopicData>(input, "topics", true)?;
85        let tagged_fields_callback = |tag: i32, _: &[u8]| {
86            match tag {
87                _ => Ok(false)
88            }
89        };
90        let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
91        Ok(AlterPartitionRequest {
92            broker_id, broker_epoch, topics, _unknown_tagged_fields
93        })
94    }
95}
96
97impl Writable for AlterPartitionRequest {
98    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
99        self.broker_id.write(output)?;
100        self.broker_epoch.write(output)?;
101        write_array(output, "self.topics", &self.topics, true)?;
102        write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
103        Ok(())
104    }
105}
106
107/// TopicData, version 2.
108#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
109#[cfg_attr(test, derive(Arbitrary))]
110pub struct TopicData {
111    /// The ID of the topic to alter ISRs for.
112    #[cfg_attr(test, proptest(strategy = "proptest_strategies::uuid()"))]
113    pub topic_id: Uuid,
114    /// The partitions to alter ISRs for.
115    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
116    pub partitions: Vec<PartitionData>,
117    /// Unknown tagged fields.
118    #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
119    pub _unknown_tagged_fields: Vec<RawTaggedField>,
120}
121
122impl Default for TopicData {
123    fn default() -> Self {
124        TopicData {
125            topic_id: Uuid::nil(),
126            partitions: Vec::<PartitionData>::new(),
127            _unknown_tagged_fields: Vec::new(),
128        }
129    }
130}
131
132impl TopicData {
133    pub fn new(topic_id: Uuid, partitions: Vec<PartitionData>) -> Self {
134        Self {
135            topic_id,
136            partitions,
137            _unknown_tagged_fields: vec![],
138        }
139    }
140}
141
142#[cfg(test)]
143mod tests_topic_data_new_and_default {
144    use super::*;
145    
146    #[test]
147    fn test() {
148        let d = TopicData::new(
149            Uuid::nil(),
150            Vec::<PartitionData>::new(),
151        );
152        assert_eq!(d, TopicData::default());
153    }
154}
155
156impl Readable for TopicData {
157    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
158        let topic_id = Uuid::read(input)?;
159        let partitions = read_array::<PartitionData>(input, "partitions", true)?;
160        let tagged_fields_callback = |tag: i32, _: &[u8]| {
161            match tag {
162                _ => Ok(false)
163            }
164        };
165        let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
166        Ok(TopicData {
167            topic_id, partitions, _unknown_tagged_fields
168        })
169    }
170}
171
172impl Writable for TopicData {
173    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
174        self.topic_id.write(output)?;
175        write_array(output, "self.partitions", &self.partitions, true)?;
176        write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
177        Ok(())
178    }
179}
180
181/// PartitionData, version 2.
182#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
183#[cfg_attr(test, derive(Arbitrary))]
184pub struct PartitionData {
185    /// The partition index.
186    pub partition_index: i32,
187    /// The leader epoch of this partition.
188    pub leader_epoch: i32,
189    /// The ISR for this partition. Deprecated since version 3.
190    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
191    pub new_isr: Vec<i32>,
192    /// 1 if the partition is recovering from an unclean leader election; 0 otherwise.
193    pub leader_recovery_state: i8,
194    /// The expected epoch of the partition which is being updated.
195    pub partition_epoch: i32,
196    /// Unknown tagged fields.
197    #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
198    pub _unknown_tagged_fields: Vec<RawTaggedField>,
199}
200
201impl Default for PartitionData {
202    fn default() -> Self {
203        PartitionData {
204            partition_index: 0_i32,
205            leader_epoch: 0_i32,
206            new_isr: Vec::<i32>::new(),
207            leader_recovery_state: 0_i8,
208            partition_epoch: 0_i32,
209            _unknown_tagged_fields: Vec::new(),
210        }
211    }
212}
213
214impl PartitionData {
215    pub fn new(partition_index: i32, leader_epoch: i32, new_isr: Vec<i32>, leader_recovery_state: i8, partition_epoch: i32) -> Self {
216        Self {
217            partition_index,
218            leader_epoch,
219            new_isr,
220            leader_recovery_state,
221            partition_epoch,
222            _unknown_tagged_fields: vec![],
223        }
224    }
225}
226
227#[cfg(test)]
228mod tests_partition_data_new_and_default {
229    use super::*;
230    
231    #[test]
232    fn test() {
233        let d = PartitionData::new(
234            0_i32,
235            0_i32,
236            Vec::<i32>::new(),
237            0_i8,
238            0_i32,
239        );
240        assert_eq!(d, PartitionData::default());
241    }
242}
243
244impl Readable for PartitionData {
245    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
246        let partition_index = i32::read(input)?;
247        let leader_epoch = i32::read(input)?;
248        let new_isr = read_array::<i32>(input, "new_isr", true)?;
249        let leader_recovery_state = i8::read(input)?;
250        let partition_epoch = i32::read(input)?;
251        let tagged_fields_callback = |tag: i32, _: &[u8]| {
252            match tag {
253                _ => Ok(false)
254            }
255        };
256        let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
257        Ok(PartitionData {
258            partition_index, leader_epoch, new_isr, leader_recovery_state, partition_epoch, _unknown_tagged_fields
259        })
260    }
261}
262
263impl Writable for PartitionData {
264    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
265        self.partition_index.write(output)?;
266        self.leader_epoch.write(output)?;
267        write_array(output, "self.new_isr", &self.new_isr, true)?;
268        self.leader_recovery_state.write(output)?;
269        self.partition_epoch.write(output)?;
270        write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
271        Ok(())
272    }
273}
274
275#[cfg(test)]
276mod tests {
277    use super::*;
278    use proptest::prelude::*;
279    
280    #[test]
281    fn test_java_default() {
282        crate::test_utils::test_java_default::<AlterPartitionRequest>("AlterPartitionRequest", 2);
283    }
284    
285    proptest! {
286        #[test]
287        fn test_serde(data: AlterPartitionRequest) {
288            crate::test_utils::test_serde(&data)?;
289        }
290    }
291    
292    proptest! {
293        #[test]
294        fn test_java_arbitrary(data: AlterPartitionRequest) {
295            crate::test_utils::test_java_arbitrary(&data, "AlterPartitionRequest", 2);
296        }
297    }
298}