Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i32, put_i32};
6use crate::primitives::string_bytes::{
7    compact_nullable_string_len, compact_string_len, nullable_string_len,
8    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
9    string_len,
10};
11use crate::primitives::string_bytes_borrowed::{
12    get_compact_nullable_string_borrowed, get_compact_string_borrowed,
13    get_nullable_string_borrowed, get_string_borrowed,
14};
15use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
16use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
17
18pub const API_KEY: i16 = 68;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 1;
21pub const FLEXIBLE_MIN: i16 = 0;
22
23#[inline]
24fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
25
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct ConsumerGroupHeartbeatRequest<'a> {
28    pub group_id: &'a str,
29    pub member_id: &'a str,
30    pub member_epoch: i32,
31    pub instance_id: Option<&'a str>,
32    pub rack_id: Option<&'a str>,
33    pub rebalance_timeout_ms: i32,
34    pub subscribed_topic_names: Option<Vec<&'a str>>,
35    pub subscribed_topic_regex: Option<&'a str>,
36    pub server_assignor: Option<&'a str>,
37    pub topic_partitions: Option<Vec<TopicPartitions>>,
38    pub unknown_tagged_fields: UnknownTaggedFields,
39}
40
41impl<'a> Default for ConsumerGroupHeartbeatRequest<'a> {
42    fn default() -> Self {
43        Self {
44            group_id: "",
45            member_id: "",
46            member_epoch: 0i32,
47            instance_id: None,
48            rack_id: None,
49            rebalance_timeout_ms: -1i32,
50            subscribed_topic_names: None,
51            subscribed_topic_regex: None,
52            server_assignor: None,
53            topic_partitions: None,
54            unknown_tagged_fields: Default::default(),
55        }
56    }
57}
58
59impl<'a> ConsumerGroupHeartbeatRequest<'a> {
60    pub fn to_owned(&self) -> crate::owned::consumer_group_heartbeat_request::ConsumerGroupHeartbeatRequest {
61        crate::owned::consumer_group_heartbeat_request::ConsumerGroupHeartbeatRequest {
62            group_id: (self.group_id).to_string(),
63            member_id: (self.member_id).to_string(),
64            member_epoch: (self.member_epoch),
65            instance_id: (self.instance_id).map(|s| s.to_string()),
66            rack_id: (self.rack_id).map(|s| s.to_string()),
67            rebalance_timeout_ms: (self.rebalance_timeout_ms),
68            subscribed_topic_names: (self.subscribed_topic_names).as_ref().map(|v| v.iter().map(|s| s.to_string()).collect()),
69            subscribed_topic_regex: (self.subscribed_topic_regex).map(|s| s.to_string()),
70            server_assignor: (self.server_assignor).map(|s| s.to_string()),
71            topic_partitions: (self.topic_partitions).as_ref().map(|v| v.iter().map(|it| it.to_owned()).collect()),
72            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
73        }
74    }
75}
76
77impl<'a> Encode for ConsumerGroupHeartbeatRequest<'a> {
78    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
79        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
80            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
81        }
82        let flex = is_flexible(version);
83        if version >= 0 { if flex { put_compact_string(buf, self.group_id) } else { put_string(buf, self.group_id) } }
84        if version >= 0 { if flex { put_compact_string(buf, self.member_id) } else { put_string(buf, self.member_id) } }
85        if version >= 0 { put_i32(buf, self.member_epoch) }
86        if version >= 0 { if flex { put_compact_nullable_string(buf, self.instance_id) } else { put_nullable_string(buf, self.instance_id) } }
87        if version >= 0 { if flex { put_compact_nullable_string(buf, self.rack_id) } else { put_nullable_string(buf, self.rack_id) } }
88        if version >= 0 { put_i32(buf, self.rebalance_timeout_ms) }
89        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) }; } } } }
90        if version >= 1 { if flex { put_compact_nullable_string(buf, self.subscribed_topic_regex) } else { put_nullable_string(buf, self.subscribed_topic_regex) } }
91        if version >= 0 { if flex { put_compact_nullable_string(buf, self.server_assignor) } else { put_nullable_string(buf, self.server_assignor) } }
92        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)?; } } } }
93        if flex {
94            let tagged = WriteTaggedFields::new();
95            tagged.write(buf, &self.unknown_tagged_fields);
96        }
97        Ok(())
98    }
99    fn encoded_len(&self, version: i16) -> usize {
100        let flex = is_flexible(version);
101        let mut n: usize = 0;
102        if version >= 0 { n += if flex { compact_string_len(self.group_id) } else { string_len(self.group_id) }; }
103        if version >= 0 { n += if flex { compact_string_len(self.member_id) } else { string_len(self.member_id) }; }
104        if version >= 0 { n += 4; }
105        if version >= 0 { n += if flex { compact_nullable_string_len(self.instance_id) } else { nullable_string_len(self.instance_id) }; }
106        if version >= 0 { n += if flex { compact_nullable_string_len(self.rack_id) } else { nullable_string_len(self.rack_id) }; }
107        if version >= 0 { n += 4; }
108        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 }; }
109        if version >= 1 { n += if flex { compact_nullable_string_len(self.subscribed_topic_regex) } else { nullable_string_len(self.subscribed_topic_regex) }; }
110        if version >= 0 { n += if flex { compact_nullable_string_len(self.server_assignor) } else { nullable_string_len(self.server_assignor) }; }
111        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 }; }
112        if flex {
113            let known_pairs: Vec<(u32, usize)> = Vec::new();
114            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
115        }
116        n
117    }
118}
119
120impl<'de> DecodeBorrow<'de> for ConsumerGroupHeartbeatRequest<'de> {
121    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
122        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
123            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
124        }
125        let flex = is_flexible(version);
126        let mut out = Self::default();
127        if version >= 0 { out.group_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
128        if version >= 0 { out.member_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
129        if version >= 0 { out.member_epoch = get_i32(buf)?; }
130        if version >= 0 { out.instance_id = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
131        if version >= 0 { out.rack_id = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
132        if version >= 0 { out.rebalance_timeout_ms = get_i32(buf)?; }
133        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_borrowed(buf)? } else { get_string_borrowed(buf)? }); } Some(v) } } }; }
134        if version >= 1 { out.subscribed_topic_regex = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
135        if version >= 0 { out.server_assignor = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
136        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_borrow(buf, version)?); } Some(v) } } }; }
137        if flex {
138            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
139                Ok(false)
140            })?;
141        }
142        Ok(out)
143    }
144}
145
146#[derive(Debug, Clone, PartialEq, Eq)]
147pub struct TopicPartitions {
148    pub topic_id: crate::primitives::uuid::Uuid,
149    pub partitions: Vec<i32>,
150    pub unknown_tagged_fields: UnknownTaggedFields,
151}
152
153impl Default for TopicPartitions {
154    fn default() -> Self {
155        Self {
156            topic_id: Default::default(),
157            partitions: Vec::new(),
158            unknown_tagged_fields: Default::default(),
159        }
160    }
161}
162
163impl TopicPartitions {
164    pub fn to_owned(&self) -> crate::owned::consumer_group_heartbeat_request::TopicPartitions {
165        crate::owned::consumer_group_heartbeat_request::TopicPartitions {
166            topic_id: (self.topic_id),
167            partitions: (self.partitions).clone(),
168            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
169        }
170    }
171}
172
173impl Encode for TopicPartitions {
174    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
175        let flex = version >= 0;
176        if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
177        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { put_i32(buf, *it); } } }
178        if flex {
179            let tagged = WriteTaggedFields::new();
180            tagged.write(buf, &self.unknown_tagged_fields);
181        }
182        Ok(())
183    }
184    fn encoded_len(&self, version: i16) -> usize {
185        let flex = version >= 0;
186        let mut n: usize = 0;
187        if version >= 0 { n += 16; }
188        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 }; }
189        if flex {
190            let known_pairs: Vec<(u32, usize)> = Vec::new();
191            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
192        }
193        n
194    }
195}
196
197impl<'de> DecodeBorrow<'de> for TopicPartitions {
198    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
199        let flex = version >= 0;
200        let mut out = Self::default();
201        if version >= 0 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
202        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 }; }
203        if flex {
204            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
205                Ok(false)
206            })?;
207        }
208        Ok(out)
209    }
210}