kafka_protocol/messages/
broker_heartbeat_response.rs

1//! BrokerHeartbeatResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/BrokerHeartbeatResponse.json).
4// WARNING: the items of this module are generated and should not be edited directly
5#![allow(unused)]
6
7use std::borrow::Borrow;
8use std::collections::BTreeMap;
9
10use anyhow::{bail, Result};
11use bytes::Bytes;
12use uuid::Uuid;
13
14use crate::protocol::{
15    buf::{ByteBuf, ByteBufMut},
16    compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder,
17    Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange,
18};
19
20/// Valid versions: 0-1
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct BrokerHeartbeatResponse {
24    /// Duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
25    ///
26    /// Supported API versions: 0-1
27    pub throttle_time_ms: i32,
28
29    /// The error code, or 0 if there was no error.
30    ///
31    /// Supported API versions: 0-1
32    pub error_code: i16,
33
34    /// True if the broker has approximately caught up with the latest metadata.
35    ///
36    /// Supported API versions: 0-1
37    pub is_caught_up: bool,
38
39    /// True if the broker is fenced.
40    ///
41    /// Supported API versions: 0-1
42    pub is_fenced: bool,
43
44    /// True if the broker should proceed with its shutdown.
45    ///
46    /// Supported API versions: 0-1
47    pub should_shut_down: bool,
48
49    /// Other tagged fields
50    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
51}
52
53impl BrokerHeartbeatResponse {
54    /// Sets `throttle_time_ms` to the passed value.
55    ///
56    /// Duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
57    ///
58    /// Supported API versions: 0-1
59    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
60        self.throttle_time_ms = value;
61        self
62    }
63    /// Sets `error_code` to the passed value.
64    ///
65    /// The error code, or 0 if there was no error.
66    ///
67    /// Supported API versions: 0-1
68    pub fn with_error_code(mut self, value: i16) -> Self {
69        self.error_code = value;
70        self
71    }
72    /// Sets `is_caught_up` to the passed value.
73    ///
74    /// True if the broker has approximately caught up with the latest metadata.
75    ///
76    /// Supported API versions: 0-1
77    pub fn with_is_caught_up(mut self, value: bool) -> Self {
78        self.is_caught_up = value;
79        self
80    }
81    /// Sets `is_fenced` to the passed value.
82    ///
83    /// True if the broker is fenced.
84    ///
85    /// Supported API versions: 0-1
86    pub fn with_is_fenced(mut self, value: bool) -> Self {
87        self.is_fenced = value;
88        self
89    }
90    /// Sets `should_shut_down` to the passed value.
91    ///
92    /// True if the broker should proceed with its shutdown.
93    ///
94    /// Supported API versions: 0-1
95    pub fn with_should_shut_down(mut self, value: bool) -> Self {
96        self.should_shut_down = value;
97        self
98    }
99    /// Sets unknown_tagged_fields to the passed value.
100    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
101        self.unknown_tagged_fields = value;
102        self
103    }
104    /// Inserts an entry into unknown_tagged_fields.
105    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
106        self.unknown_tagged_fields.insert(key, value);
107        self
108    }
109}
110
111#[cfg(feature = "broker")]
112impl Encodable for BrokerHeartbeatResponse {
113    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
114        if version < 0 || version > 1 {
115            bail!("specified version not supported by this message type");
116        }
117        types::Int32.encode(buf, &self.throttle_time_ms)?;
118        types::Int16.encode(buf, &self.error_code)?;
119        types::Boolean.encode(buf, &self.is_caught_up)?;
120        types::Boolean.encode(buf, &self.is_fenced)?;
121        types::Boolean.encode(buf, &self.should_shut_down)?;
122        let num_tagged_fields = self.unknown_tagged_fields.len();
123        if num_tagged_fields > std::u32::MAX as usize {
124            bail!(
125                "Too many tagged fields to encode ({} fields)",
126                num_tagged_fields
127            );
128        }
129        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
130
131        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
132        Ok(())
133    }
134    fn compute_size(&self, version: i16) -> Result<usize> {
135        let mut total_size = 0;
136        total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
137        total_size += types::Int16.compute_size(&self.error_code)?;
138        total_size += types::Boolean.compute_size(&self.is_caught_up)?;
139        total_size += types::Boolean.compute_size(&self.is_fenced)?;
140        total_size += types::Boolean.compute_size(&self.should_shut_down)?;
141        let num_tagged_fields = self.unknown_tagged_fields.len();
142        if num_tagged_fields > std::u32::MAX as usize {
143            bail!(
144                "Too many tagged fields to encode ({} fields)",
145                num_tagged_fields
146            );
147        }
148        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
149
150        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
151        Ok(total_size)
152    }
153}
154
155#[cfg(feature = "client")]
156impl Decodable for BrokerHeartbeatResponse {
157    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
158        if version < 0 || version > 1 {
159            bail!("specified version not supported by this message type");
160        }
161        let throttle_time_ms = types::Int32.decode(buf)?;
162        let error_code = types::Int16.decode(buf)?;
163        let is_caught_up = types::Boolean.decode(buf)?;
164        let is_fenced = types::Boolean.decode(buf)?;
165        let should_shut_down = types::Boolean.decode(buf)?;
166        let mut unknown_tagged_fields = BTreeMap::new();
167        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
168        for _ in 0..num_tagged_fields {
169            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
170            let size: u32 = types::UnsignedVarInt.decode(buf)?;
171            let unknown_value = buf.try_get_bytes(size as usize)?;
172            unknown_tagged_fields.insert(tag as i32, unknown_value);
173        }
174        Ok(Self {
175            throttle_time_ms,
176            error_code,
177            is_caught_up,
178            is_fenced,
179            should_shut_down,
180            unknown_tagged_fields,
181        })
182    }
183}
184
185impl Default for BrokerHeartbeatResponse {
186    fn default() -> Self {
187        Self {
188            throttle_time_ms: 0,
189            error_code: 0,
190            is_caught_up: false,
191            is_fenced: true,
192            should_shut_down: false,
193            unknown_tagged_fields: BTreeMap::new(),
194        }
195    }
196}
197
198impl Message for BrokerHeartbeatResponse {
199    const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
200    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
201}
202
203impl HeaderVersion for BrokerHeartbeatResponse {
204    fn header_version(version: i16) -> i16 {
205        1
206    }
207}