kafka_wire_protocol/schema/list_offsets_request/
v4.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};
11#[cfg(test)] use crate::test_utils::proptest_strategies;
12
13/// ListOffsetsRequest, version 4.
14#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
15#[cfg_attr(test, derive(Arbitrary))]
16pub struct ListOffsetsRequest {
17    /// The broker ID of the requester, or -1 if this request is being made by a normal consumer.
18    pub replica_id: i32,
19    /// This setting controls the visibility of transactional records. Using READ_UNCOMMITTED (isolation_level = 0) makes all records visible. With READ_COMMITTED (isolation_level = 1), non-transactional and COMMITTED transactional records are visible. To be more concrete, READ_COMMITTED returns all data from offsets smaller than the current LSO (last stable offset), and enables the inclusion of the list of aborted transactions in the result, which allows consumers to discard ABORTED transactional records.
20    pub isolation_level: i8,
21    /// Each topic in the request.
22    #[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        4
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/// ListOffsetsTopic, version 4.
94#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
95#[cfg_attr(test, derive(Arbitrary))]
96pub struct ListOffsetsTopic {
97    /// The topic name.
98    #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
99    pub name: String,
100    /// Each partition in the request.
101    #[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/// ListOffsetsPartition, version 4.
156#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
157#[cfg_attr(test, derive(Arbitrary))]
158pub struct ListOffsetsPartition {
159    /// The partition index.
160    pub partition_index: i32,
161    /// The current leader epoch.
162    pub current_leader_epoch: i32,
163    /// The current timestamp.
164    pub timestamp: i64,
165}
166
167impl Default for ListOffsetsPartition {
168    fn default() -> Self {
169        ListOffsetsPartition {
170            partition_index: 0_i32,
171            current_leader_epoch: -1_i32,
172            timestamp: 0_i64,
173        }
174    }
175}
176
177impl ListOffsetsPartition {
178    pub fn new(partition_index: i32, current_leader_epoch: i32, timestamp: i64) -> Self {
179        Self {
180            partition_index,
181            current_leader_epoch,
182            timestamp,
183        }
184    }
185}
186
187#[cfg(test)]
188mod tests_list_offsets_partition_new_and_default {
189    use super::*;
190    
191    #[test]
192    fn test() {
193        let d = ListOffsetsPartition::new(
194            0_i32,
195            -1_i32,
196            0_i64,
197        );
198        assert_eq!(d, ListOffsetsPartition::default());
199    }
200}
201
202impl Readable for ListOffsetsPartition {
203    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
204        let partition_index = i32::read(input)?;
205        let current_leader_epoch = i32::read(input)?;
206        let timestamp = i64::read(input)?;
207        Ok(ListOffsetsPartition {
208            partition_index, current_leader_epoch, timestamp
209        })
210    }
211}
212
213impl Writable for ListOffsetsPartition {
214    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
215        self.partition_index.write(output)?;
216        self.current_leader_epoch.write(output)?;
217        self.timestamp.write(output)?;
218        Ok(())
219    }
220}
221
222#[cfg(test)]
223mod tests {
224    use super::*;
225    use proptest::prelude::*;
226    
227    #[test]
228    fn test_java_default() {
229        crate::test_utils::test_java_default::<ListOffsetsRequest>("ListOffsetsRequest", 4);
230    }
231    
232    proptest! {
233        #[test]
234        fn test_serde(data: ListOffsetsRequest) {
235            crate::test_utils::test_serde(&data)?;
236        }
237    }
238    
239    proptest! {
240        #[test]
241        fn test_java_arbitrary(data: ListOffsetsRequest) {
242            crate::test_utils::test_java_arbitrary(&data, "ListOffsetsRequest", 4);
243        }
244    }
245}