Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ConsumerGroupHeartbeatRequest.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i32, put_i32};
6use crate::primitives::string_bytes::{
7    compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8    get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
10    string_len,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 68;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 1;
18pub const FLEXIBLE_MIN: i16 = 0;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct ConsumerGroupHeartbeatRequest {
25    pub group_id: String,
26    pub member_id: String,
27    pub member_epoch: i32,
28    pub instance_id: Option<String>,
29    pub rack_id: Option<String>,
30    pub rebalance_timeout_ms: i32,
31    pub subscribed_topic_names: Option<Vec<String>>,
32    pub subscribed_topic_regex: Option<String>,
33    pub server_assignor: Option<String>,
34    pub topic_partitions: Option<Vec<TopicPartitions>>,
35    pub unknown_tagged_fields: UnknownTaggedFields,
36}
37
38impl Default for ConsumerGroupHeartbeatRequest {
39    fn default() -> Self {
40        Self {
41            group_id: String::new(),
42            member_id: String::new(),
43            member_epoch: 0i32,
44            instance_id: None,
45            rack_id: None,
46            rebalance_timeout_ms: -1i32,
47            subscribed_topic_names: None,
48            subscribed_topic_regex: None,
49            server_assignor: None,
50            topic_partitions: None,
51            unknown_tagged_fields: Default::default(),
52        }
53    }
54}
55
56impl Encode for ConsumerGroupHeartbeatRequest {
57    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
58        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
59            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
60        }
61        let flex = is_flexible(version);
62        if version >= 0 { if flex { put_compact_string(buf, &self.group_id) } else { put_string(buf, &self.group_id) } }
63        if version >= 0 { if flex { put_compact_string(buf, &self.member_id) } else { put_string(buf, &self.member_id) } }
64        if version >= 0 { put_i32(buf, self.member_epoch) }
65        if version >= 0 { if flex { put_compact_nullable_string(buf, self.instance_id.as_deref()) } else { put_nullable_string(buf, self.instance_id.as_deref()) } }
66        if version >= 0 { if flex { put_compact_nullable_string(buf, self.rack_id.as_deref()) } else { put_nullable_string(buf, self.rack_id.as_deref()) } }
67        if version >= 0 { put_i32(buf, self.rebalance_timeout_ms) }
68        if version >= 0 { { let len = (self.subscribed_topic_names).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.subscribed_topic_names { for it in v { if flex { put_compact_string(buf, &*it) } else { put_string(buf, &*it) }; } } } }
69        if version >= 1 { if flex { put_compact_nullable_string(buf, self.subscribed_topic_regex.as_deref()) } else { put_nullable_string(buf, self.subscribed_topic_regex.as_deref()) } }
70        if version >= 0 { if flex { put_compact_nullable_string(buf, self.server_assignor.as_deref()) } else { put_nullable_string(buf, self.server_assignor.as_deref()) } }
71        if version >= 0 { { let len = (self.topic_partitions).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.topic_partitions { for it in v { it.encode(buf, version)?; } } } }
72        if flex {
73            let tagged = WriteTaggedFields::new();
74            tagged.write(buf, &self.unknown_tagged_fields);
75        }
76        Ok(())
77    }
78    fn encoded_len(&self, version: i16) -> usize {
79        let flex = is_flexible(version);
80        let mut n: usize = 0;
81        if version >= 0 { n += if flex { compact_string_len(&self.group_id) } else { string_len(&self.group_id) }; }
82        if version >= 0 { n += if flex { compact_string_len(&self.member_id) } else { string_len(&self.member_id) }; }
83        if version >= 0 { n += 4; }
84        if version >= 0 { n += if flex { compact_nullable_string_len(self.instance_id.as_deref()) } else { nullable_string_len(self.instance_id.as_deref()) }; }
85        if version >= 0 { n += if flex { compact_nullable_string_len(self.rack_id.as_deref()) } else { nullable_string_len(self.rack_id.as_deref()) }; }
86        if version >= 0 { n += 4; }
87        if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.subscribed_topic_names).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| if flex { compact_string_len(&*it) } else { string_len(&*it) }).sum()); prefix + body }; }
88        if version >= 1 { n += if flex { compact_nullable_string_len(self.subscribed_topic_regex.as_deref()) } else { nullable_string_len(self.subscribed_topic_regex.as_deref()) }; }
89        if version >= 0 { n += if flex { compact_nullable_string_len(self.server_assignor.as_deref()) } else { nullable_string_len(self.server_assignor.as_deref()) }; }
90        if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.topic_partitions).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum()); prefix + body }; }
91        if flex {
92            let known_pairs: Vec<(u32, usize)> = Vec::new();
93            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
94        }
95        n
96    }
97}
98
99impl<'de> Decode<'de> for ConsumerGroupHeartbeatRequest {
100    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
101        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
102            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
103        }
104        let flex = is_flexible(version);
105        let mut out = Self::default();
106        if version >= 0 { out.group_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
107        if version >= 0 { out.member_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
108        if version >= 0 { out.member_epoch = get_i32(buf)?; }
109        if version >= 0 { out.instance_id = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
110        if version >= 0 { out.rack_id = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
111        if version >= 0 { out.rebalance_timeout_ms = get_i32(buf)?; }
112        if version >= 0 { out.subscribed_topic_names = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }); } Some(v) } } }; }
113        if version >= 1 { out.subscribed_topic_regex = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
114        if version >= 0 { out.server_assignor = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
115        if version >= 0 { out.topic_partitions = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(TopicPartitions::decode(buf, version)?); } Some(v) } } }; }
116        if flex {
117            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
118                Ok(false)
119            })?;
120        }
121        Ok(out)
122    }
123}
124
125#[derive(Debug, Clone, PartialEq, Eq, Default)]
126pub struct TopicPartitions {
127    pub topic_id: crate::primitives::uuid::Uuid,
128    pub partitions: Vec<i32>,
129    pub unknown_tagged_fields: UnknownTaggedFields,
130}
131
132impl Encode for TopicPartitions {
133    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
134        let flex = version >= 0;
135        if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
136        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { put_i32(buf, *it); } } }
137        if flex {
138            let tagged = WriteTaggedFields::new();
139            tagged.write(buf, &self.unknown_tagged_fields);
140        }
141        Ok(())
142    }
143    fn encoded_len(&self, version: i16) -> usize {
144        let flex = version >= 0;
145        let mut n: usize = 0;
146        if version >= 0 { n += 16; }
147        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex); let body: usize = (self.partitions).iter().map(|_| 4).sum(); prefix + body }; }
148        if flex {
149            let known_pairs: Vec<(u32, usize)> = Vec::new();
150            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
151        }
152        n
153    }
154}
155
156impl<'de> Decode<'de> for TopicPartitions {
157    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
158        let flex = version >= 0;
159        let mut out = Self::default();
160        if version >= 0 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
161        if version >= 0 { out.partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } v }; }
162        if flex {
163            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
164                Ok(false)
165            })?;
166        }
167        Ok(out)
168    }
169}
170
171/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
172/// Only includes fields valid for the given version.
173#[must_use]
174#[allow(unused_comparisons)]
175pub fn default_json(version: i16) -> ::serde_json::Value {
176    let mut obj = ::serde_json::Map::new();
177    obj.insert("groupId".to_string(), ::serde_json::Value::String(String::new()));
178    obj.insert("memberId".to_string(), ::serde_json::Value::String(String::new()));
179    obj.insert("memberEpoch".to_string(), ::serde_json::json!(0));
180    obj.insert("instanceId".to_string(), ::serde_json::Value::Null);
181    obj.insert("rackId".to_string(), ::serde_json::Value::Null);
182    obj.insert("rebalanceTimeoutMs".to_string(), ::serde_json::json!(-1));
183    obj.insert("subscribedTopicNames".to_string(), ::serde_json::Value::Null);
184    if version >= 1 {
185        obj.insert("subscribedTopicRegex".to_string(), ::serde_json::Value::Null);
186    }
187    obj.insert("serverAssignor".to_string(), ::serde_json::Value::Null);
188    obj.insert("topicPartitions".to_string(), ::serde_json::Value::Null);
189    ::serde_json::Value::Object(obj)
190}
191
192impl crate::ProtocolRequest for ConsumerGroupHeartbeatRequest {
193    const API_KEY: i16 = API_KEY;
194    const MIN_VERSION: i16 = MIN_VERSION;
195    const MAX_VERSION: i16 = MAX_VERSION;
196    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
197    type Response = super::consumer_group_heartbeat_response::ConsumerGroupHeartbeatResponse;
198}