Skip to main content

odradek_protocol/messages/
heartbeat_response.rs

1//! `HeartbeatResponse` — generated from `schemas/HeartbeatResponse.json`.
2//!
3//! @generated by `cargo xtask codegen`. Do not edit by hand.
4
5#![allow(
6    clippy::field_reassign_with_default,
7    clippy::nonminimal_bool,
8    clippy::derivable_impls,
9    clippy::borrow_deref_ref,
10    clippy::double_parens,
11    unused_parens
12)]
13
14use bytes::{Buf, BufMut};
15
16use crate::budget::{Budget, Limits};
17#[allow(unused_imports)]
18use crate::error::{DecodeError, EncodeError};
19use crate::wire::{self, RawTaggedField};
20
21/// Whether `version` of this message uses the flexible (compact) encoding.
22pub fn is_flexible(version: i16) -> bool {
23    let _ = version;
24    version >= 4
25}
26
27/// `HeartbeatResponse`, versions 0-4.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct HeartbeatResponse {
31    /// 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.
32    pub throttle_time_ms: i32,
33    /// The error code, or 0 if there was no error.
34    pub error_code: i16,
35    /// Tagged fields not (yet) known to this crate, kept raw.
36    pub unknown_tagged_fields: Vec<RawTaggedField>,
37}
38
39impl Default for HeartbeatResponse {
40    fn default() -> Self {
41        Self {
42            throttle_time_ms: 0,
43            error_code: 0,
44            unknown_tagged_fields: Vec::new(),
45        }
46    }
47}
48
49impl HeartbeatResponse {
50    /// This message's api key in Kafka's registry.
51    pub const API_KEY: i16 = 12;
52    /// The lowest schema version this snapshot can speak.
53    pub const MIN_VERSION: i16 = 0;
54    /// The highest schema version this snapshot can speak.
55    pub const MAX_VERSION: i16 = 4;
56
57    /// Encode this `HeartbeatResponse` at `version`.
58    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
59        if version >= 1 {
60            buf.put_i32(self.throttle_time_ms);
61        }
62        buf.put_i16(self.error_code);
63        if is_flexible(version) {
64            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
65        }
66        Ok(())
67    }
68
69    /// Decode one `HeartbeatResponse`, bounding allocation by the default
70    /// [`Limits`] derived from `buf`'s remaining length.
71    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
72        Self::decode_with_limits(buf, version, Limits::default())
73    }
74
75    /// Decode one `HeartbeatResponse` under `limits`.
76    pub fn decode_with_limits(
77        buf: &mut impl Buf,
78        version: i16,
79        limits: Limits,
80    ) -> Result<Self, DecodeError> {
81        let mut budget = limits.budget(buf.remaining());
82        Self::decode_with_budget(buf, version, &mut budget)
83    }
84
85    /// Decode one `HeartbeatResponse` against an existing `budget`.
86    pub fn decode_with_budget(
87        buf: &mut impl Buf,
88        version: i16,
89        budget: &mut Budget,
90    ) -> Result<Self, DecodeError> {
91        let mut this = Self::default();
92        if version >= 1 {
93            this.throttle_time_ms = wire::get_i32(buf)?;
94        }
95        this.error_code = wire::get_i16(buf)?;
96        if is_flexible(version) {
97            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
98        }
99        Ok(this)
100    }
101}
102
103impl crate::Message for HeartbeatResponse {
104    const API_KEY: i16 = 12;
105    const MIN_VERSION: i16 = 0;
106    const MAX_VERSION: i16 = 4;
107
108    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
109        HeartbeatResponse::encode(self, buf, version)
110    }
111    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
112        HeartbeatResponse::decode(buf, version)
113    }
114    fn decode_with_limits(
115        buf: &mut impl Buf,
116        version: i16,
117        limits: Limits,
118    ) -> Result<Self, DecodeError> {
119        HeartbeatResponse::decode_with_limits(buf, version, limits)
120    }
121    fn throttle_time_ms(&self) -> Option<i32> {
122        Some(self.throttle_time_ms)
123    }
124}