kafka_wire_protocol/schema/list_offsets_request/
v2.rs1use 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};
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 ListOffsetsRequest {
17 pub replica_id: i32,
19 pub isolation_level: i8,
21 #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
23 pub topics: Vec<ListOffsetsTopic>,
24}
25
26impl ApiMessage for ListOffsetsRequest {
27 fn api_key(&self) -> i16 {
28 2
29 }
30
31 fn version(&self) -> i16 {
32 2
33 }
34}
35
36impl Request for ListOffsetsRequest { }
37
38impl Default for ListOffsetsRequest {
39 fn default() -> Self {
40 ListOffsetsRequest {
41 replica_id: 0_i32,
42 isolation_level: 0_i8,
43 topics: Vec::<ListOffsetsTopic>::new(),
44 }
45 }
46}
47
48impl ListOffsetsRequest {
49 pub fn new(replica_id: i32, isolation_level: i8, topics: Vec<ListOffsetsTopic>) -> Self {
50 Self {
51 replica_id,
52 isolation_level,
53 topics,
54 }
55 }
56}
57
58#[cfg(test)]
59mod tests_list_offsets_request_new_and_default {
60 use super::*;
61
62 #[test]
63 fn test() {
64 let d = ListOffsetsRequest::new(
65 0_i32,
66 0_i8,
67 Vec::<ListOffsetsTopic>::new(),
68 );
69 assert_eq!(d, ListOffsetsRequest::default());
70 }
71}
72
73impl Readable for ListOffsetsRequest {
74 fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
75 let replica_id = i32::read(input)?;
76 let isolation_level = i8::read(input)?;
77 let topics = read_array::<ListOffsetsTopic>(input, "topics", false)?;
78 Ok(ListOffsetsRequest {
79 replica_id, isolation_level, topics
80 })
81 }
82}
83
84impl Writable for ListOffsetsRequest {
85 fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
86 self.replica_id.write(output)?;
87 self.isolation_level.write(output)?;
88 write_array(output, "self.topics", &self.topics, false)?;
89 Ok(())
90 }
91}
92
93#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
95#[cfg_attr(test, derive(Arbitrary))]
96pub struct ListOffsetsTopic {
97 #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
99 pub name: String,
100 #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
102 pub partitions: Vec<ListOffsetsPartition>,
103}
104
105impl Default for ListOffsetsTopic {
106 fn default() -> Self {
107 ListOffsetsTopic {
108 name: String::from(""),
109 partitions: Vec::<ListOffsetsPartition>::new(),
110 }
111 }
112}
113
114impl ListOffsetsTopic {
115 pub fn new<S1: AsRef<str>>(name: S1, partitions: Vec<ListOffsetsPartition>) -> Self {
116 Self {
117 name: name.as_ref().to_string(),
118 partitions,
119 }
120 }
121}
122
123#[cfg(test)]
124mod tests_list_offsets_topic_new_and_default {
125 use super::*;
126
127 #[test]
128 fn test() {
129 let d = ListOffsetsTopic::new(
130 String::from(""),
131 Vec::<ListOffsetsPartition>::new(),
132 );
133 assert_eq!(d, ListOffsetsTopic::default());
134 }
135}
136
137impl Readable for ListOffsetsTopic {
138 fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
139 let name = String::read_ext(input, "name", false)?;
140 let partitions = read_array::<ListOffsetsPartition>(input, "partitions", false)?;
141 Ok(ListOffsetsTopic {
142 name, partitions
143 })
144 }
145}
146
147impl Writable for ListOffsetsTopic {
148 fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
149 self.name.write_ext(output, "self.name", false)?;
150 write_array(output, "self.partitions", &self.partitions, false)?;
151 Ok(())
152 }
153}
154
155#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
157#[cfg_attr(test, derive(Arbitrary))]
158pub struct ListOffsetsPartition {
159 pub partition_index: i32,
161 pub timestamp: i64,
163}
164
165impl Default for ListOffsetsPartition {
166 fn default() -> Self {
167 ListOffsetsPartition {
168 partition_index: 0_i32,
169 timestamp: 0_i64,
170 }
171 }
172}
173
174impl ListOffsetsPartition {
175 pub fn new(partition_index: i32, timestamp: i64) -> Self {
176 Self {
177 partition_index,
178 timestamp,
179 }
180 }
181}
182
183#[cfg(test)]
184mod tests_list_offsets_partition_new_and_default {
185 use super::*;
186
187 #[test]
188 fn test() {
189 let d = ListOffsetsPartition::new(
190 0_i32,
191 0_i64,
192 );
193 assert_eq!(d, ListOffsetsPartition::default());
194 }
195}
196
197impl Readable for ListOffsetsPartition {
198 fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
199 let partition_index = i32::read(input)?;
200 let timestamp = i64::read(input)?;
201 Ok(ListOffsetsPartition {
202 partition_index, timestamp
203 })
204 }
205}
206
207impl Writable for ListOffsetsPartition {
208 fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
209 self.partition_index.write(output)?;
210 self.timestamp.write(output)?;
211 Ok(())
212 }
213}
214
215#[cfg(test)]
216mod tests {
217 use super::*;
218 use proptest::prelude::*;
219
220 #[test]
221 fn test_java_default() {
222 crate::test_utils::test_java_default::<ListOffsetsRequest>("ListOffsetsRequest", 2);
223 }
224
225 proptest! {
226 #[test]
227 fn test_serde(data: ListOffsetsRequest) {
228 crate::test_utils::test_serde(&data)?;
229 }
230 }
231
232 proptest! {
233 #[test]
234 fn test_java_arbitrary(data: ListOffsetsRequest) {
235 crate::test_utils::test_java_arbitrary(&data, "ListOffsetsRequest", 2);
236 }
237 }
238}