kafka_protocol/messages/
share_group_heartbeat_request.rs

1//! ShareGroupHeartbeatRequest
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/ShareGroupHeartbeatRequest.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: 1
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct ShareGroupHeartbeatRequest {
24    /// The group identifier.
25    ///
26    /// Supported API versions: 1
27    pub group_id: super::GroupId,
28
29    /// The member id generated by the consumer. The member id must be kept during the entire lifetime of the consumer process.
30    ///
31    /// Supported API versions: 1
32    pub member_id: StrBytes,
33
34    /// The current member epoch; 0 to join the group; -1 to leave the group.
35    ///
36    /// Supported API versions: 1
37    pub member_epoch: i32,
38
39    /// null if not provided or if it didn't change since the last heartbeat; the rack ID of consumer otherwise.
40    ///
41    /// Supported API versions: 1
42    pub rack_id: Option<StrBytes>,
43
44    /// null if it didn't change since the last heartbeat; the subscribed topic names otherwise.
45    ///
46    /// Supported API versions: 1
47    pub subscribed_topic_names: Option<Vec<super::TopicName>>,
48
49    /// Other tagged fields
50    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
51}
52
53impl ShareGroupHeartbeatRequest {
54    /// Sets `group_id` to the passed value.
55    ///
56    /// The group identifier.
57    ///
58    /// Supported API versions: 1
59    pub fn with_group_id(mut self, value: super::GroupId) -> Self {
60        self.group_id = value;
61        self
62    }
63    /// Sets `member_id` to the passed value.
64    ///
65    /// The member id generated by the consumer. The member id must be kept during the entire lifetime of the consumer process.
66    ///
67    /// Supported API versions: 1
68    pub fn with_member_id(mut self, value: StrBytes) -> Self {
69        self.member_id = value;
70        self
71    }
72    /// Sets `member_epoch` to the passed value.
73    ///
74    /// The current member epoch; 0 to join the group; -1 to leave the group.
75    ///
76    /// Supported API versions: 1
77    pub fn with_member_epoch(mut self, value: i32) -> Self {
78        self.member_epoch = value;
79        self
80    }
81    /// Sets `rack_id` to the passed value.
82    ///
83    /// null if not provided or if it didn't change since the last heartbeat; the rack ID of consumer otherwise.
84    ///
85    /// Supported API versions: 1
86    pub fn with_rack_id(mut self, value: Option<StrBytes>) -> Self {
87        self.rack_id = value;
88        self
89    }
90    /// Sets `subscribed_topic_names` to the passed value.
91    ///
92    /// null if it didn't change since the last heartbeat; the subscribed topic names otherwise.
93    ///
94    /// Supported API versions: 1
95    pub fn with_subscribed_topic_names(mut self, value: Option<Vec<super::TopicName>>) -> Self {
96        self.subscribed_topic_names = 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 = "client")]
112impl Encodable for ShareGroupHeartbeatRequest {
113    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
114        if version != 1 {
115            bail!("specified version not supported by this message type");
116        }
117        types::CompactString.encode(buf, &self.group_id)?;
118        types::CompactString.encode(buf, &self.member_id)?;
119        types::Int32.encode(buf, &self.member_epoch)?;
120        types::CompactString.encode(buf, &self.rack_id)?;
121        types::CompactArray(types::CompactString).encode(buf, &self.subscribed_topic_names)?;
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::CompactString.compute_size(&self.group_id)?;
137        total_size += types::CompactString.compute_size(&self.member_id)?;
138        total_size += types::Int32.compute_size(&self.member_epoch)?;
139        total_size += types::CompactString.compute_size(&self.rack_id)?;
140        total_size +=
141            types::CompactArray(types::CompactString).compute_size(&self.subscribed_topic_names)?;
142        let num_tagged_fields = self.unknown_tagged_fields.len();
143        if num_tagged_fields > std::u32::MAX as usize {
144            bail!(
145                "Too many tagged fields to encode ({} fields)",
146                num_tagged_fields
147            );
148        }
149        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
150
151        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
152        Ok(total_size)
153    }
154}
155
156#[cfg(feature = "broker")]
157impl Decodable for ShareGroupHeartbeatRequest {
158    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
159        if version != 1 {
160            bail!("specified version not supported by this message type");
161        }
162        let group_id = types::CompactString.decode(buf)?;
163        let member_id = types::CompactString.decode(buf)?;
164        let member_epoch = types::Int32.decode(buf)?;
165        let rack_id = types::CompactString.decode(buf)?;
166        let subscribed_topic_names = types::CompactArray(types::CompactString).decode(buf)?;
167        let mut unknown_tagged_fields = BTreeMap::new();
168        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
169        for _ in 0..num_tagged_fields {
170            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
171            let size: u32 = types::UnsignedVarInt.decode(buf)?;
172            let unknown_value = buf.try_get_bytes(size as usize)?;
173            unknown_tagged_fields.insert(tag as i32, unknown_value);
174        }
175        Ok(Self {
176            group_id,
177            member_id,
178            member_epoch,
179            rack_id,
180            subscribed_topic_names,
181            unknown_tagged_fields,
182        })
183    }
184}
185
186impl Default for ShareGroupHeartbeatRequest {
187    fn default() -> Self {
188        Self {
189            group_id: Default::default(),
190            member_id: Default::default(),
191            member_epoch: 0,
192            rack_id: None,
193            subscribed_topic_names: None,
194            unknown_tagged_fields: BTreeMap::new(),
195        }
196    }
197}
198
199impl Message for ShareGroupHeartbeatRequest {
200    const VERSIONS: VersionRange = VersionRange { min: 1, max: 1 };
201    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
202}
203
204impl HeaderVersion for ShareGroupHeartbeatRequest {
205    fn header_version(version: i16) -> i16 {
206        2
207    }
208}