kafka_wire_protocol/schema/elect_leaders_request/
v0.rs1use std::io::{Read, Result, Write};
4
5use serde::{Deserialize, Serialize};
6#[cfg(test)] use proptest_derive::Arbitrary;
7
8use crate::arrays::{read_array, read_nullable_array, write_array, write_nullable_array};
9use crate::markers::{ApiMessage, Request};
10use crate::readable_writable::{Readable, Writable};
11#[cfg(test)] use crate::test_utils::proptest_strategies;
12
13#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
15#[cfg_attr(test, derive(Arbitrary))]
16pub struct ElectLeadersRequest {
17 #[cfg_attr(test, proptest(strategy = "proptest_strategies::optional_vec()"))]
19 pub topic_partitions: Option<Vec<TopicPartitions>>,
20 pub timeout_ms: i32,
22}
23
24impl ApiMessage for ElectLeadersRequest {
25 fn api_key(&self) -> i16 {
26 43
27 }
28
29 fn version(&self) -> i16 {
30 0
31 }
32}
33
34impl Request for ElectLeadersRequest { }
35
36impl Default for ElectLeadersRequest {
37 fn default() -> Self {
38 ElectLeadersRequest {
39 topic_partitions: Some(Vec::<TopicPartitions>::new()),
40 timeout_ms: 60000_i32,
41 }
42 }
43}
44
45impl ElectLeadersRequest {
46 pub fn new(topic_partitions: Option<Vec<TopicPartitions>>, timeout_ms: i32) -> Self {
47 Self {
48 topic_partitions,
49 timeout_ms,
50 }
51 }
52}
53
54#[cfg(test)]
55mod tests_elect_leaders_request_new_and_default {
56 use super::*;
57
58 #[test]
59 fn test() {
60 let d = ElectLeadersRequest::new(
61 Some(Vec::<TopicPartitions>::new()),
62 60000_i32,
63 );
64 assert_eq!(d, ElectLeadersRequest::default());
65 }
66}
67
68impl Readable for ElectLeadersRequest {
69 fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
70 let topic_partitions = read_nullable_array::<TopicPartitions>(input, "topic_partitions", false)?;
71 let timeout_ms = i32::read(input)?;
72 Ok(ElectLeadersRequest {
73 topic_partitions, timeout_ms
74 })
75 }
76}
77
78impl Writable for ElectLeadersRequest {
79 fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
80 write_nullable_array(output, "self.topic_partitions", self.topic_partitions.as_deref(), false)?;
81 self.timeout_ms.write(output)?;
82 Ok(())
83 }
84}
85
86#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
88#[cfg_attr(test, derive(Arbitrary))]
89pub struct TopicPartitions {
90 #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
92 pub topic: String,
93 #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
95 pub partitions: Vec<i32>,
96}
97
98impl Default for TopicPartitions {
99 fn default() -> Self {
100 TopicPartitions {
101 topic: String::from(""),
102 partitions: Vec::<i32>::new(),
103 }
104 }
105}
106
107impl TopicPartitions {
108 pub fn new<S1: AsRef<str>>(topic: S1, partitions: Vec<i32>) -> Self {
109 Self {
110 topic: topic.as_ref().to_string(),
111 partitions,
112 }
113 }
114}
115
116#[cfg(test)]
117mod tests_topic_partitions_new_and_default {
118 use super::*;
119
120 #[test]
121 fn test() {
122 let d = TopicPartitions::new(
123 String::from(""),
124 Vec::<i32>::new(),
125 );
126 assert_eq!(d, TopicPartitions::default());
127 }
128}
129
130impl Readable for TopicPartitions {
131 fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
132 let topic = String::read_ext(input, "topic", false)?;
133 let partitions = read_array::<i32>(input, "partitions", false)?;
134 Ok(TopicPartitions {
135 topic, partitions
136 })
137 }
138}
139
140impl Writable for TopicPartitions {
141 fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
142 self.topic.write_ext(output, "self.topic", false)?;
143 write_array(output, "self.partitions", &self.partitions, false)?;
144 Ok(())
145 }
146}
147
148#[cfg(test)]
149mod tests {
150 use super::*;
151 use proptest::prelude::*;
152
153 #[test]
154 fn test_java_default() {
155 crate::test_utils::test_java_default::<ElectLeadersRequest>("ElectLeadersRequest", 0);
156 }
157
158 proptest! {
159 #[test]
160 fn test_serde(data: ElectLeadersRequest) {
161 crate::test_utils::test_serde(&data)?;
162 }
163 }
164
165 proptest! {
166 #[test]
167 fn test_java_arbitrary(data: ElectLeadersRequest) {
168 crate::test_utils::test_java_arbitrary(&data, "ElectLeadersRequest", 0);
169 }
170 }
171}