kafka_wire_protocol/schema/vote_request/
v0.rs

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