kafka_wire_protocol/schema/metadata_response/
v10.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/// MetadataResponse, version 10.
16#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
17#[cfg_attr(test, derive(Arbitrary))]
18pub struct MetadataResponse {
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    /// A list of brokers present in the cluster.
22    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
23    pub brokers: Vec<MetadataResponseBroker>,
24    /// The cluster ID that responding broker belongs to.
25    #[cfg_attr(test, proptest(strategy = "proptest_strategies::optional_string()"))]
26    pub cluster_id: Option<String>,
27    /// The ID of the controller broker.
28    pub controller_id: i32,
29    /// Each topic in the response.
30    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
31    pub topics: Vec<MetadataResponseTopic>,
32    /// 32-bit bitfield to represent authorized operations for this cluster.
33    pub cluster_authorized_operations: i32,
34    /// Unknown tagged fields.
35    #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
36    pub _unknown_tagged_fields: Vec<RawTaggedField>,
37}
38
39impl ApiMessage for MetadataResponse {
40    fn api_key(&self) -> i16 {
41        3
42    }
43    
44    fn version(&self) -> i16 {
45        10
46    }
47}
48
49impl Response for MetadataResponse { }
50
51impl Default for MetadataResponse {
52    fn default() -> Self {
53        MetadataResponse {
54            throttle_time_ms: 0_i32,
55            brokers: Vec::<MetadataResponseBroker>::new(),
56            cluster_id: None,
57            controller_id: -1_i32,
58            topics: Vec::<MetadataResponseTopic>::new(),
59            cluster_authorized_operations: -2147483648_i32,
60            _unknown_tagged_fields: Vec::new(),
61        }
62    }
63}
64
65impl MetadataResponse {
66    pub fn new<S1: AsRef<str>>(throttle_time_ms: i32, brokers: Vec<MetadataResponseBroker>, cluster_id: Option<S1>, controller_id: i32, topics: Vec<MetadataResponseTopic>, cluster_authorized_operations: i32) -> Self {
67        Self {
68            throttle_time_ms,
69            brokers,
70            cluster_id: cluster_id.map(|s| s.as_ref().to_string()),
71            controller_id,
72            topics,
73            cluster_authorized_operations,
74            _unknown_tagged_fields: vec![],
75        }
76    }
77}
78
79#[cfg(test)]
80mod tests_metadata_response_new_and_default {
81    use super::*;
82    
83    #[test]
84    fn test() {
85        let d = MetadataResponse::new(
86            0_i32,
87            Vec::<MetadataResponseBroker>::new(),
88            None::<String>,
89            -1_i32,
90            Vec::<MetadataResponseTopic>::new(),
91            -2147483648_i32,
92        );
93        assert_eq!(d, MetadataResponse::default());
94    }
95}
96
97impl Readable for MetadataResponse {
98    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
99        let throttle_time_ms = i32::read(input)?;
100        let brokers = read_array::<MetadataResponseBroker>(input, "brokers", true)?;
101        let cluster_id = Option::<String>::read_ext(input, "cluster_id", true)?;
102        let controller_id = i32::read(input)?;
103        let topics = read_array::<MetadataResponseTopic>(input, "topics", true)?;
104        let cluster_authorized_operations = i32::read(input)?;
105        let tagged_fields_callback = |tag: i32, _: &[u8]| {
106            match tag {
107                _ => Ok(false)
108            }
109        };
110        let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
111        Ok(MetadataResponse {
112            throttle_time_ms, brokers, cluster_id, controller_id, topics, cluster_authorized_operations, _unknown_tagged_fields
113        })
114    }
115}
116
117impl Writable for MetadataResponse {
118    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
119        self.throttle_time_ms.write(output)?;
120        write_array(output, "self.brokers", &self.brokers, true)?;
121        self.cluster_id.write_ext(output, "self.cluster_id", true)?;
122        self.controller_id.write(output)?;
123        write_array(output, "self.topics", &self.topics, true)?;
124        self.cluster_authorized_operations.write(output)?;
125        write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
126        Ok(())
127    }
128}
129
130/// MetadataResponseBroker, version 10.
131#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
132#[cfg_attr(test, derive(Arbitrary))]
133pub struct MetadataResponseBroker {
134    /// The broker ID.
135    pub node_id: i32,
136    /// The broker hostname.
137    #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
138    pub host: String,
139    /// The broker port.
140    pub port: i32,
141    /// The rack of the broker, or null if it has not been assigned to a rack.
142    #[cfg_attr(test, proptest(strategy = "proptest_strategies::optional_string()"))]
143    pub rack: Option<String>,
144    /// Unknown tagged fields.
145    #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
146    pub _unknown_tagged_fields: Vec<RawTaggedField>,
147}
148
149impl Default for MetadataResponseBroker {
150    fn default() -> Self {
151        MetadataResponseBroker {
152            node_id: 0_i32,
153            host: String::from(""),
154            port: 0_i32,
155            rack: None,
156            _unknown_tagged_fields: Vec::new(),
157        }
158    }
159}
160
161impl MetadataResponseBroker {
162    pub fn new<S1: AsRef<str>, S2: AsRef<str>>(node_id: i32, host: S1, port: i32, rack: Option<S2>) -> Self {
163        Self {
164            node_id,
165            host: host.as_ref().to_string(),
166            port,
167            rack: rack.map(|s| s.as_ref().to_string()),
168            _unknown_tagged_fields: vec![],
169        }
170    }
171}
172
173#[cfg(test)]
174mod tests_metadata_response_broker_new_and_default {
175    use super::*;
176    
177    #[test]
178    fn test() {
179        let d = MetadataResponseBroker::new(
180            0_i32,
181            String::from(""),
182            0_i32,
183            None::<String>,
184        );
185        assert_eq!(d, MetadataResponseBroker::default());
186    }
187}
188
189impl Readable for MetadataResponseBroker {
190    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
191        let node_id = i32::read(input)?;
192        let host = String::read_ext(input, "host", true)?;
193        let port = i32::read(input)?;
194        let rack = Option::<String>::read_ext(input, "rack", true)?;
195        let tagged_fields_callback = |tag: i32, _: &[u8]| {
196            match tag {
197                _ => Ok(false)
198            }
199        };
200        let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
201        Ok(MetadataResponseBroker {
202            node_id, host, port, rack, _unknown_tagged_fields
203        })
204    }
205}
206
207impl Writable for MetadataResponseBroker {
208    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
209        self.node_id.write(output)?;
210        self.host.write_ext(output, "self.host", true)?;
211        self.port.write(output)?;
212        self.rack.write_ext(output, "self.rack", true)?;
213        write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
214        Ok(())
215    }
216}
217
218/// MetadataResponseTopic, version 10.
219#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
220#[cfg_attr(test, derive(Arbitrary))]
221pub struct MetadataResponseTopic {
222    /// The topic error, or 0 if there was no error.
223    pub error_code: i16,
224    /// The topic name. Null for non-existing topics queried by ID. This is never null when ErrorCode is zero. One of Name and TopicId is always populated.
225    #[cfg_attr(test, proptest(strategy = "proptest_strategies::string()"))]
226    pub name: String,
227    /// The topic id. Zero for non-existing topics queried by name. This is never zero when ErrorCode is zero. One of Name and TopicId is always populated.
228    #[cfg_attr(test, proptest(strategy = "proptest_strategies::uuid()"))]
229    pub topic_id: Uuid,
230    /// True if the topic is internal.
231    pub is_internal: bool,
232    /// Each partition in the topic.
233    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
234    pub partitions: Vec<MetadataResponsePartition>,
235    /// 32-bit bitfield to represent authorized operations for this topic.
236    pub topic_authorized_operations: i32,
237    /// Unknown tagged fields.
238    #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
239    pub _unknown_tagged_fields: Vec<RawTaggedField>,
240}
241
242impl Default for MetadataResponseTopic {
243    fn default() -> Self {
244        MetadataResponseTopic {
245            error_code: 0_i16,
246            name: String::from(""),
247            topic_id: Uuid::nil(),
248            is_internal: false,
249            partitions: Vec::<MetadataResponsePartition>::new(),
250            topic_authorized_operations: -2147483648_i32,
251            _unknown_tagged_fields: Vec::new(),
252        }
253    }
254}
255
256impl MetadataResponseTopic {
257    pub fn new<S1: AsRef<str>>(error_code: i16, name: S1, topic_id: Uuid, is_internal: bool, partitions: Vec<MetadataResponsePartition>, topic_authorized_operations: i32) -> Self {
258        Self {
259            error_code,
260            name: name.as_ref().to_string(),
261            topic_id,
262            is_internal,
263            partitions,
264            topic_authorized_operations,
265            _unknown_tagged_fields: vec![],
266        }
267    }
268}
269
270#[cfg(test)]
271mod tests_metadata_response_topic_new_and_default {
272    use super::*;
273    
274    #[test]
275    fn test() {
276        let d = MetadataResponseTopic::new(
277            0_i16,
278            String::from(""),
279            Uuid::nil(),
280            false,
281            Vec::<MetadataResponsePartition>::new(),
282            -2147483648_i32,
283        );
284        assert_eq!(d, MetadataResponseTopic::default());
285    }
286}
287
288impl Readable for MetadataResponseTopic {
289    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
290        let error_code = i16::read(input)?;
291        let name = String::read_ext(input, "name", true)?;
292        let topic_id = Uuid::read(input)?;
293        let is_internal = bool::read(input)?;
294        let partitions = read_array::<MetadataResponsePartition>(input, "partitions", true)?;
295        let topic_authorized_operations = i32::read(input)?;
296        let tagged_fields_callback = |tag: i32, _: &[u8]| {
297            match tag {
298                _ => Ok(false)
299            }
300        };
301        let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
302        Ok(MetadataResponseTopic {
303            error_code, name, topic_id, is_internal, partitions, topic_authorized_operations, _unknown_tagged_fields
304        })
305    }
306}
307
308impl Writable for MetadataResponseTopic {
309    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
310        self.error_code.write(output)?;
311        self.name.write_ext(output, "self.name", true)?;
312        self.topic_id.write(output)?;
313        self.is_internal.write(output)?;
314        write_array(output, "self.partitions", &self.partitions, true)?;
315        self.topic_authorized_operations.write(output)?;
316        write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
317        Ok(())
318    }
319}
320
321/// MetadataResponsePartition, version 10.
322#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
323#[cfg_attr(test, derive(Arbitrary))]
324pub struct MetadataResponsePartition {
325    /// The partition error, or 0 if there was no error.
326    pub error_code: i16,
327    /// The partition index.
328    pub partition_index: i32,
329    /// The ID of the leader broker.
330    pub leader_id: i32,
331    /// The leader epoch of this partition.
332    pub leader_epoch: i32,
333    /// The set of all nodes that host this partition.
334    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
335    pub replica_nodes: Vec<i32>,
336    /// The set of nodes that are in sync with the leader for this partition.
337    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
338    pub isr_nodes: Vec<i32>,
339    /// The set of offline replicas of this partition.
340    #[cfg_attr(test, proptest(strategy = "proptest_strategies::vec()"))]
341    pub offline_replicas: Vec<i32>,
342    /// Unknown tagged fields.
343    #[cfg_attr(test, proptest(strategy = "proptest_strategies::unknown_tagged_fields()"))]
344    pub _unknown_tagged_fields: Vec<RawTaggedField>,
345}
346
347impl Default for MetadataResponsePartition {
348    fn default() -> Self {
349        MetadataResponsePartition {
350            error_code: 0_i16,
351            partition_index: 0_i32,
352            leader_id: 0_i32,
353            leader_epoch: -1_i32,
354            replica_nodes: Vec::<i32>::new(),
355            isr_nodes: Vec::<i32>::new(),
356            offline_replicas: Vec::<i32>::new(),
357            _unknown_tagged_fields: Vec::new(),
358        }
359    }
360}
361
362impl MetadataResponsePartition {
363    pub fn new(error_code: i16, partition_index: i32, leader_id: i32, leader_epoch: i32, replica_nodes: Vec<i32>, isr_nodes: Vec<i32>, offline_replicas: Vec<i32>) -> Self {
364        Self {
365            error_code,
366            partition_index,
367            leader_id,
368            leader_epoch,
369            replica_nodes,
370            isr_nodes,
371            offline_replicas,
372            _unknown_tagged_fields: vec![],
373        }
374    }
375}
376
377#[cfg(test)]
378mod tests_metadata_response_partition_new_and_default {
379    use super::*;
380    
381    #[test]
382    fn test() {
383        let d = MetadataResponsePartition::new(
384            0_i16,
385            0_i32,
386            0_i32,
387            -1_i32,
388            Vec::<i32>::new(),
389            Vec::<i32>::new(),
390            Vec::<i32>::new(),
391        );
392        assert_eq!(d, MetadataResponsePartition::default());
393    }
394}
395
396impl Readable for MetadataResponsePartition {
397    fn read(#[allow(unused)] input: &mut impl Read) -> Result<Self> {
398        let error_code = i16::read(input)?;
399        let partition_index = i32::read(input)?;
400        let leader_id = i32::read(input)?;
401        let leader_epoch = i32::read(input)?;
402        let replica_nodes = read_array::<i32>(input, "replica_nodes", true)?;
403        let isr_nodes = read_array::<i32>(input, "isr_nodes", true)?;
404        let offline_replicas = read_array::<i32>(input, "offline_replicas", true)?;
405        let tagged_fields_callback = |tag: i32, _: &[u8]| {
406            match tag {
407                _ => Ok(false)
408            }
409        };
410        let _unknown_tagged_fields = read_tagged_fields(input, tagged_fields_callback)?;
411        Ok(MetadataResponsePartition {
412            error_code, partition_index, leader_id, leader_epoch, replica_nodes, isr_nodes, offline_replicas, _unknown_tagged_fields
413        })
414    }
415}
416
417impl Writable for MetadataResponsePartition {
418    fn write(&self, #[allow(unused)] output: &mut impl Write) -> Result<()> {
419        self.error_code.write(output)?;
420        self.partition_index.write(output)?;
421        self.leader_id.write(output)?;
422        self.leader_epoch.write(output)?;
423        write_array(output, "self.replica_nodes", &self.replica_nodes, true)?;
424        write_array(output, "self.isr_nodes", &self.isr_nodes, true)?;
425        write_array(output, "self.offline_replicas", &self.offline_replicas, true)?;
426        write_tagged_fields(output, &[], &self._unknown_tagged_fields)?;
427        Ok(())
428    }
429}
430
431#[cfg(test)]
432mod tests {
433    use super::*;
434    use proptest::prelude::*;
435    
436    #[test]
437    fn test_java_default() {
438        crate::test_utils::test_java_default::<MetadataResponse>("MetadataResponse", 10);
439    }
440    
441    proptest! {
442        #[test]
443        fn test_serde(data: MetadataResponse) {
444            crate::test_utils::test_serde(&data)?;
445        }
446    }
447    
448    proptest! {
449        #[test]
450        fn test_java_arbitrary(data: MetadataResponse) {
451            crate::test_utils::test_java_arbitrary(&data, "MetadataResponse", 10);
452        }
453    }
454}