kafka_api/schemata/
find_coordinator_response.rs1use byteorder::WriteBytesExt;
16
17use crate::codec::*;
18use crate::IoResult;
19
20#[derive(Debug, Default, Clone)]
29pub struct FindCoordinatorResponse {
30 pub throttle_time_ms: i32,
33 pub error_code: i16,
35 pub error_message: Option<String>,
37 pub node_id: i32,
39 pub host: String,
41 pub port: i32,
43 pub coordinators: Vec<Coordinator>,
45 pub unknown_tagged_fields: Vec<RawTaggedField>,
47}
48
49impl Encodable for FindCoordinatorResponse {
50 fn write<B: WriteBytesExt>(&self, buf: &mut B, version: i16) -> IoResult<()> {
51 if version >= 1 {
52 Int32.encode(buf, self.throttle_time_ms)?;
53 }
54 if version <= 3 {
55 Int16.encode(buf, self.error_code)?;
56 }
57 if (1..=3).contains(&version) {
58 NullableString(version >= 3).encode(buf, self.error_message.as_deref())?;
59 }
60 if version <= 3 {
61 Int32.encode(buf, self.node_id)?;
62 }
63 if version <= 3 {
64 NullableString(version >= 3).encode(buf, self.host.as_str())?;
65 }
66 if version <= 3 {
67 Int32.encode(buf, self.port)?;
68 }
69 if version >= 4 {
70 NullableArray(Struct(version), true).encode(buf, self.coordinators.as_slice())?;
71 }
72 if version >= 3 {
73 RawTaggedFieldList.encode(buf, &self.unknown_tagged_fields)?;
74 }
75 Ok(())
76 }
77
78 fn calculate_size(&self, version: i16) -> usize {
79 let mut res = 0;
80 if version >= 1 {
81 res += Int32::SIZE; }
83 if version <= 3 {
84 res += Int16::SIZE; }
86 if (1..=3).contains(&version) {
87 res += NullableString(version >= 3).calculate_size(self.error_message.as_deref());
88 }
89 if version <= 3 {
90 res += Int32::SIZE; }
92 if version <= 3 {
93 res += NullableString(version >= 3).calculate_size(self.host.as_str());
94 }
95 if version <= 3 {
96 res += Int32::SIZE; }
98 if version >= 4 {
99 res +=
100 NullableArray(Struct(version), true).calculate_size(self.coordinators.as_slice());
101 }
102 if version >= 3 {
103 res += RawTaggedFieldList.calculate_size(&self.unknown_tagged_fields);
104 }
105 res
106 }
107}
108
109#[derive(Debug, Default, Clone)]
110pub struct Coordinator {
111 pub key: String,
113 pub node_id: i32,
115 pub host: String,
117 pub port: i32,
119 pub error_code: i16,
121 pub error_message: Option<String>,
123 pub unknown_tagged_fields: Vec<RawTaggedField>,
125}
126
127impl Encodable for Coordinator {
128 fn write<B: WriteBytesExt>(&self, buf: &mut B, version: i16) -> IoResult<()> {
129 if version > 4 {
130 Err(err_encode_message_unsupported(version, "Coordinator"))?
131 }
132 NullableString(true).encode(buf, self.key.as_str())?;
133 Int32.encode(buf, self.node_id)?;
134 NullableString(true).encode(buf, self.host.as_str())?;
135 Int32.encode(buf, self.port)?;
136 Int16.encode(buf, self.error_code)?;
137 NullableString(true).encode(buf, self.error_message.as_deref())?;
138 RawTaggedFieldList.encode(buf, &self.unknown_tagged_fields)?;
139 Ok(())
140 }
141
142 fn calculate_size(&self, _version: i16) -> usize {
143 let mut res = 0;
144 res += NullableString(true).calculate_size(self.key.as_str());
145 res += Int32::SIZE; res += NullableString(true).calculate_size(self.host.as_str());
147 res += Int32::SIZE; res += Int16::SIZE; res += NullableString(true).calculate_size(self.error_message.as_deref());
150 res += RawTaggedFieldList.calculate_size(&self.unknown_tagged_fields);
151 res
152 }
153}