Skip to main content

odradek_protocol/messages/
heartbeat_request.rs

1//! `HeartbeatRequest` — generated from `schemas/HeartbeatRequest.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/// `HeartbeatRequest`, versions 0-4.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct HeartbeatRequest {
31    /// The group id.
32    pub group_id: String,
33    /// The generation of the group.
34    pub generation_id: i32,
35    /// The member ID.
36    pub member_id: String,
37    /// The unique identifier of the consumer instance provided by end user.
38    pub group_instance_id: Option<String>,
39    /// Tagged fields not (yet) known to this crate, kept raw.
40    pub unknown_tagged_fields: Vec<RawTaggedField>,
41}
42
43impl Default for HeartbeatRequest {
44    fn default() -> Self {
45        Self {
46            group_id: String::new(),
47            generation_id: 0,
48            member_id: String::new(),
49            group_instance_id: None,
50            unknown_tagged_fields: Vec::new(),
51        }
52    }
53}
54
55impl HeartbeatRequest {
56    /// This message's api key in Kafka's registry.
57    pub const API_KEY: i16 = 12;
58    /// The lowest schema version this snapshot can speak.
59    pub const MIN_VERSION: i16 = 0;
60    /// The highest schema version this snapshot can speak.
61    pub const MAX_VERSION: i16 = 4;
62
63    /// Encode this `HeartbeatRequest` at `version`.
64    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
65        if is_flexible(version) {
66            wire::put_compact_string(buf, &self.group_id);
67        } else {
68            wire::put_string(buf, &self.group_id)?;
69        }
70        buf.put_i32(self.generation_id);
71        if is_flexible(version) {
72            wire::put_compact_string(buf, &self.member_id);
73        } else {
74            wire::put_string(buf, &self.member_id)?;
75        }
76        if version >= 3 {
77            if is_flexible(version) {
78                wire::put_compact_nullable_string(buf, self.group_instance_id.as_deref());
79            } else {
80                wire::put_nullable_string(buf, self.group_instance_id.as_deref())?;
81            }
82        }
83        if is_flexible(version) {
84            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
85        }
86        Ok(())
87    }
88
89    /// Decode one `HeartbeatRequest`, bounding allocation by the default
90    /// [`Limits`] derived from `buf`'s remaining length.
91    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
92        Self::decode_with_limits(buf, version, Limits::default())
93    }
94
95    /// Decode one `HeartbeatRequest` under `limits`.
96    pub fn decode_with_limits(
97        buf: &mut impl Buf,
98        version: i16,
99        limits: Limits,
100    ) -> Result<Self, DecodeError> {
101        let mut budget = limits.budget(buf.remaining());
102        Self::decode_with_budget(buf, version, &mut budget)
103    }
104
105    /// Decode one `HeartbeatRequest` against an existing `budget`.
106    pub fn decode_with_budget(
107        buf: &mut impl Buf,
108        version: i16,
109        budget: &mut Budget,
110    ) -> Result<Self, DecodeError> {
111        let mut this = Self::default();
112        this.group_id = if is_flexible(version) {
113            wire::get_compact_string(buf)?
114        } else {
115            wire::get_string(buf)?
116        };
117        this.generation_id = wire::get_i32(buf)?;
118        this.member_id = if is_flexible(version) {
119            wire::get_compact_string(buf)?
120        } else {
121            wire::get_string(buf)?
122        };
123        if version >= 3 {
124            this.group_instance_id = if is_flexible(version) {
125                wire::get_compact_nullable_string(buf)?
126            } else {
127                wire::get_nullable_string(buf)?
128            };
129        }
130        if is_flexible(version) {
131            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
132        }
133        Ok(this)
134    }
135}
136
137impl crate::Message for HeartbeatRequest {
138    const API_KEY: i16 = 12;
139    const MIN_VERSION: i16 = 0;
140    const MAX_VERSION: i16 = 4;
141
142    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
143        HeartbeatRequest::encode(self, buf, version)
144    }
145    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
146        HeartbeatRequest::decode(buf, version)
147    }
148    fn decode_with_limits(
149        buf: &mut impl Buf,
150        version: i16,
151        limits: Limits,
152    ) -> Result<Self, DecodeError> {
153        HeartbeatRequest::decode_with_limits(buf, version, limits)
154    }
155}