kafka_wire_protocol/schema/alter_partition_response/
v3.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, Response};
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/// AlterPartitionResponse, version 3.
16#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
17#[cfg_attr(test, derive(Arbitrary))]
18pub struct AlterPartitionResponse {
19    /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
20    pub throttle_time_ms: i32,
21    /// The top level response error code.
22    pub error_code: i16,
23    /// The responses for each topic.
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 AlterPartitionResponse {
32    fn api_key(&self) -> i16 {
33        56
34    }
35    
36    fn version(&self) -> i16 {
37        3
38    }
39}
40
41impl Response for AlterPartitionResponse { }
42
43impl Default for AlterPartitionResponse {
44    fn default() -> Self {
45        AlterPartitionResponse {
46            throttle_time_ms: 0_i32,
47            error_code: 0_i16,
48            topics: Vec::<TopicData>::new(),
49            _unknown_tagged_fields: Vec::new(),
50        }
51    }
52}
53
54impl AlterPartitionResponse {
55    pub fn new(throttle_time_ms: i32, error_code: i16, topics: Vec<TopicData>) -> Self {
56        Self {
57            throttle_time_ms,
58            error_code,
59            topics,
60            _unknown_tagged_fields: vec![],
61        }
62    }
63}
64
65#[cfg(test)]
66mod tests_alter_partition_response_new_and_default {
67    use super::*;
68    
69    #[test]
70    fn test() {
71        let d = AlterPartitionResponse::new(
72            0_i32,
73            0_i16,
74            Vec::<TopicData>::new(),
75        );
76        assert_eq!(d, AlterPartitionResponse::default());
77    }
78}
79
80impl Readable for AlterPartitionResponse {
81    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
82        let throttle_time_ms = i32::read(input)?;
83        let error_code = i16::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(AlterPartitionResponse {
92            throttle_time_ms, error_code, topics, _unknown_tagged_fields
93        })
94    }
95}
96
97impl Writable for AlterPartitionResponse {
98    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
99        self.throttle_time_ms.write(output)?;
100        self.error_code.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 3.
108#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
109#[cfg_attr(test, derive(Arbitrary))]
110pub struct TopicData {
111    /// The ID of the topic.
112    #[cfg_attr(test, proptest(strategy = "proptest_strategies::uuid()"))]
113    pub topic_id: Uuid,
114    /// The responses for each partition.
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 3.
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 partition level error code.
188    pub error_code: i16,
189    /// The broker ID of the leader.
190    pub leader_id: i32,
191    /// The leader epoch.
192    pub leader_epoch: i32,
193    /// The in-sync replica IDs.
194    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
195    pub isr: Vec<i32>,
196    /// 1 if the partition is recovering from an unclean leader election; 0 otherwise.
197    pub leader_recovery_state: i8,
198    /// The current epoch for the partition for KRaft controllers.
199    pub partition_epoch: i32,
200    /// Unknown tagged fields.
201    #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
202    pub _unknown_tagged_fields: Vec<RawTaggedField>,
203}
204
205impl Default for PartitionData {
206    fn default() -> Self {
207        PartitionData {
208            partition_index: 0_i32,
209            error_code: 0_i16,
210            leader_id: 0_i32,
211            leader_epoch: 0_i32,
212            isr: Vec::<i32>::new(),
213            leader_recovery_state: 0_i8,
214            partition_epoch: 0_i32,
215            _unknown_tagged_fields: Vec::new(),
216        }
217    }
218}
219
220impl PartitionData {
221    pub fn new(partition_index: i32, error_code: i16, leader_id: i32, leader_epoch: i32, isr: Vec<i32>, leader_recovery_state: i8, partition_epoch: i32) -> Self {
222        Self {
223            partition_index,
224            error_code,
225            leader_id,
226            leader_epoch,
227            isr,
228            leader_recovery_state,
229            partition_epoch,
230            _unknown_tagged_fields: vec![],
231        }
232    }
233}
234
235#[cfg(test)]
236mod tests_partition_data_new_and_default {
237    use super::*;
238    
239    #[test]
240    fn test() {
241        let d = PartitionData::new(
242            0_i32,
243            0_i16,
244            0_i32,
245            0_i32,
246            Vec::<i32>::new(),
247            0_i8,
248            0_i32,
249        );
250        assert_eq!(d, PartitionData::default());
251    }
252}
253
254impl Readable for PartitionData {
255    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
256        let partition_index = i32::read(input)?;
257        let error_code = i16::read(input)?;
258        let leader_id = i32::read(input)?;
259        let leader_epoch = i32::read(input)?;
260        let isr = read_array::<i32>(input, "isr", true)?;
261        let leader_recovery_state = i8::read(input)?;
262        let partition_epoch = i32::read(input)?;
263        let tagged_fields_callback = |tag: i32, _: &[u8]| {
264            match tag {
265                _ => Ok(false)
266            }
267        };
268        let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
269        Ok(PartitionData {
270            partition_index, error_code, leader_id, leader_epoch, isr, leader_recovery_state, partition_epoch, _unknown_tagged_fields
271        })
272    }
273}
274
275impl Writable for PartitionData {
276    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
277        self.partition_index.write(output)?;
278        self.error_code.write(output)?;
279        self.leader_id.write(output)?;
280        self.leader_epoch.write(output)?;
281        write_array(output, "self.isr", &self.isr, true)?;
282        self.leader_recovery_state.write(output)?;
283        self.partition_epoch.write(output)?;
284        write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
285        Ok(())
286    }
287}
288
289#[cfg(test)]
290mod tests {
291    use super::*;
292    use proptest::prelude::*;
293    
294    #[test]
295    fn test_java_default() {
296        crate::test_utils::test_java_default::<AlterPartitionResponse>("AlterPartitionResponse", 3);
297    }
298    
299    proptest! {
300        #[test]
301        fn test_serde(data: AlterPartitionResponse) {
302            crate::test_utils::test_serde(&data)?;
303        }
304    }
305    
306    proptest! {
307        #[test]
308        fn test_java_arbitrary(data: AlterPartitionResponse) {
309            crate::test_utils::test_java_arbitrary(&data, "AlterPartitionResponse", 3);
310        }
311    }
312}