odradek_protocol/messages/
consumer_group_heartbeat_response.rs1#![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
21pub fn is_flexible(version: i16) -> bool {
23 let _ = version;
24 true
25}
26
27#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct ConsumerGroupHeartbeatResponse {
31 pub throttle_time_ms: i32,
33 pub error_code: i16,
35 pub error_message: Option<String>,
37 pub member_id: Option<String>,
39 pub member_epoch: i32,
41 pub heartbeat_interval_ms: i32,
43 pub assignment: Option<Assignment>,
45 pub unknown_tagged_fields: Vec<RawTaggedField>,
47}
48
49impl Default for ConsumerGroupHeartbeatResponse {
50 fn default() -> Self {
51 Self {
52 throttle_time_ms: 0,
53 error_code: 0,
54 error_message: None,
55 member_id: None,
56 member_epoch: 0,
57 heartbeat_interval_ms: 0,
58 assignment: None,
59 unknown_tagged_fields: Vec::new(),
60 }
61 }
62}
63
64impl ConsumerGroupHeartbeatResponse {
65 pub const API_KEY: i16 = 68;
67 pub const MIN_VERSION: i16 = 0;
69 pub const MAX_VERSION: i16 = 1;
71
72 pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
74 buf.put_i32(self.throttle_time_ms);
75 buf.put_i16(self.error_code);
76 if is_flexible(version) {
77 wire::put_compact_nullable_string(buf, self.error_message.as_deref());
78 } else {
79 wire::put_nullable_string(buf, self.error_message.as_deref())?;
80 }
81 if is_flexible(version) {
82 wire::put_compact_nullable_string(buf, self.member_id.as_deref());
83 } else {
84 wire::put_nullable_string(buf, self.member_id.as_deref())?;
85 }
86 buf.put_i32(self.member_epoch);
87 buf.put_i32(self.heartbeat_interval_ms);
88 match &self.assignment {
89 Some(v) => {
90 buf.put_i8(1);
91 v.encode(buf, version)?;
92 }
93 None => {
94 buf.put_i8(-1);
95 }
96 }
97 if is_flexible(version) {
98 wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
99 }
100 Ok(())
101 }
102
103 pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
106 Self::decode_with_limits(buf, version, Limits::default())
107 }
108
109 pub fn decode_with_limits(
111 buf: &mut impl Buf,
112 version: i16,
113 limits: Limits,
114 ) -> Result<Self, DecodeError> {
115 let mut budget = limits.budget(buf.remaining());
116 Self::decode_with_budget(buf, version, &mut budget)
117 }
118
119 pub fn decode_with_budget(
121 buf: &mut impl Buf,
122 version: i16,
123 budget: &mut Budget,
124 ) -> Result<Self, DecodeError> {
125 let mut this = Self::default();
126 this.throttle_time_ms = wire::get_i32(buf)?;
127 this.error_code = wire::get_i16(buf)?;
128 this.error_message = if is_flexible(version) {
129 wire::get_compact_nullable_string(buf)?
130 } else {
131 wire::get_nullable_string(buf)?
132 };
133 this.member_id = if is_flexible(version) {
134 wire::get_compact_nullable_string(buf)?
135 } else {
136 wire::get_nullable_string(buf)?
137 };
138 this.member_epoch = wire::get_i32(buf)?;
139 this.heartbeat_interval_ms = wire::get_i32(buf)?;
140 this.assignment = if wire::get_i8(buf)? < 0 {
141 None
142 } else {
143 Some(Assignment::decode_with_budget(buf, version, budget)?)
144 };
145 if is_flexible(version) {
146 this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
147 }
148 Ok(this)
149 }
150}
151
152impl crate::Message for ConsumerGroupHeartbeatResponse {
153 const API_KEY: i16 = 68;
154 const MIN_VERSION: i16 = 0;
155 const MAX_VERSION: i16 = 1;
156
157 fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
158 ConsumerGroupHeartbeatResponse::encode(self, buf, version)
159 }
160 fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
161 ConsumerGroupHeartbeatResponse::decode(buf, version)
162 }
163 fn decode_with_limits(
164 buf: &mut impl Buf,
165 version: i16,
166 limits: Limits,
167 ) -> Result<Self, DecodeError> {
168 ConsumerGroupHeartbeatResponse::decode_with_limits(buf, version, limits)
169 }
170 fn throttle_time_ms(&self) -> Option<i32> {
171 Some(self.throttle_time_ms)
172 }
173}
174
175#[derive(Debug, Clone, PartialEq)]
177#[non_exhaustive]
178pub struct Assignment {
179 pub topic_partitions: Vec<TopicPartitions>,
181 pub unknown_tagged_fields: Vec<RawTaggedField>,
183}
184
185impl Default for Assignment {
186 fn default() -> Self {
187 Self {
188 topic_partitions: Vec::new(),
189 unknown_tagged_fields: Vec::new(),
190 }
191 }
192}
193
194impl Assignment {
195 pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
197 if is_flexible(version) {
198 wire::put_compact_array_len(buf, Some(self.topic_partitions.len()));
199 } else {
200 wire::put_array_len(buf, Some(self.topic_partitions.len()))?;
201 }
202 for item in &self.topic_partitions {
203 item.encode(buf, version)?;
204 }
205 if is_flexible(version) {
206 wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
207 }
208 Ok(())
209 }
210
211 pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
214 Self::decode_with_limits(buf, version, Limits::default())
215 }
216
217 pub fn decode_with_limits(
219 buf: &mut impl Buf,
220 version: i16,
221 limits: Limits,
222 ) -> Result<Self, DecodeError> {
223 let mut budget = limits.budget(buf.remaining());
224 Self::decode_with_budget(buf, version, &mut budget)
225 }
226
227 pub fn decode_with_budget(
229 buf: &mut impl Buf,
230 version: i16,
231 budget: &mut Budget,
232 ) -> Result<Self, DecodeError> {
233 let mut this = Self::default();
234 this.topic_partitions = {
235 let len = if is_flexible(version) {
236 wire::get_compact_array_len(buf)?
237 } else {
238 wire::get_array_len(buf)?
239 };
240 match len {
241 None => return Err(DecodeError::InvalidLength(-1)),
242 Some(n) => {
243 let mut items = Vec::new();
244 for _ in 0..n {
245 let mark = buf.remaining();
246 let item = TopicPartitions::decode_with_budget(buf, version, budget)?;
247 budget.progress(mark, buf.remaining())?;
248 budget.push(&mut items, item)?;
249 }
250 items
251 }
252 }
253 };
254 if is_flexible(version) {
255 this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
256 }
257 Ok(this)
258 }
259}
260
261#[derive(Debug, Clone, PartialEq)]
263#[non_exhaustive]
264pub struct TopicPartitions {
265 pub topic_id: [u8; 16],
267 pub partitions: Vec<i32>,
269 pub unknown_tagged_fields: Vec<RawTaggedField>,
271}
272
273impl Default for TopicPartitions {
274 fn default() -> Self {
275 Self {
276 topic_id: [0u8; 16],
277 partitions: Vec::new(),
278 unknown_tagged_fields: Vec::new(),
279 }
280 }
281}
282
283impl TopicPartitions {
284 pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
286 wire::put_uuid(buf, self.topic_id);
287 if is_flexible(version) {
288 wire::put_compact_array_len(buf, Some(self.partitions.len()));
289 } else {
290 wire::put_array_len(buf, Some(self.partitions.len()))?;
291 }
292 for item in &self.partitions {
293 buf.put_i32(*item);
294 }
295 if is_flexible(version) {
296 wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
297 }
298 Ok(())
299 }
300
301 pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
304 Self::decode_with_limits(buf, version, Limits::default())
305 }
306
307 pub fn decode_with_limits(
309 buf: &mut impl Buf,
310 version: i16,
311 limits: Limits,
312 ) -> Result<Self, DecodeError> {
313 let mut budget = limits.budget(buf.remaining());
314 Self::decode_with_budget(buf, version, &mut budget)
315 }
316
317 pub fn decode_with_budget(
319 buf: &mut impl Buf,
320 version: i16,
321 budget: &mut Budget,
322 ) -> Result<Self, DecodeError> {
323 let mut this = Self::default();
324 this.topic_id = wire::get_uuid(buf)?;
325 this.partitions = {
326 let len = if is_flexible(version) {
327 wire::get_compact_array_len(buf)?
328 } else {
329 wire::get_array_len(buf)?
330 };
331 match len {
332 None => return Err(DecodeError::InvalidLength(-1)),
333 Some(n) => {
334 let mut items = Vec::new();
335 for _ in 0..n {
336 budget.push(&mut items, wire::get_i32(buf)?)?;
337 }
338 items
339 }
340 }
341 };
342 if is_flexible(version) {
343 this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
344 }
345 Ok(this)
346 }
347}