crabka_protocol/opt/rustwide/workdir/generated/
ConsumerGroupHeartbeatResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, get_i8, put_i16, 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, Default)]
24pub struct ConsumerGroupHeartbeatResponse {
25 pub throttle_time_ms: i32,
26 pub error_code: i16,
27 pub error_message: Option<String>,
28 pub member_id: Option<String>,
29 pub member_epoch: i32,
30 pub heartbeat_interval_ms: i32,
31 pub assignment: Option<Assignment>,
32 pub unknown_tagged_fields: UnknownTaggedFields,
33}
34
35impl Encode for ConsumerGroupHeartbeatResponse {
36 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
37 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
38 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
39 }
40 let flex = is_flexible(version);
41 if version >= 0 { put_i32(buf, self.throttle_time_ms) }
42 if version >= 0 { put_i16(buf, self.error_code) }
43 if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message.as_deref()) } else { put_nullable_string(buf, self.error_message.as_deref()) } }
44 if version >= 0 { if flex { put_compact_nullable_string(buf, self.member_id.as_deref()) } else { put_nullable_string(buf, self.member_id.as_deref()) } }
45 if version >= 0 { put_i32(buf, self.member_epoch) }
46 if version >= 0 { put_i32(buf, self.heartbeat_interval_ms) }
47 if version >= 0 { match &self.assignment { None => { buf.put_i8(-1); }, Some(v) => { buf.put_i8(1); v.encode(buf, version)?; } } }
48 if flex {
49 let tagged = WriteTaggedFields::new();
50 tagged.write(buf, &self.unknown_tagged_fields);
51 }
52 Ok(())
53 }
54 fn encoded_len(&self, version: i16) -> usize {
55 let flex = is_flexible(version);
56 let mut n: usize = 0;
57 if version >= 0 { n += 4; }
58 if version >= 0 { n += 2; }
59 if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message.as_deref()) } else { nullable_string_len(self.error_message.as_deref()) }; }
60 if version >= 0 { n += if flex { compact_nullable_string_len(self.member_id.as_deref()) } else { nullable_string_len(self.member_id.as_deref()) }; }
61 if version >= 0 { n += 4; }
62 if version >= 0 { n += 4; }
63 if version >= 0 { n += 1 + self.assignment.as_ref().map_or(0, |v| v.encoded_len(version)); }
64 if flex {
65 let known_pairs: Vec<(u32, usize)> = Vec::new();
66 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
67 }
68 n
69 }
70}
71
72impl<'de> Decode<'de> for ConsumerGroupHeartbeatResponse {
73 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
74 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
75 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
76 }
77 let flex = is_flexible(version);
78 let mut out = Self::default();
79 if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
80 if version >= 0 { out.error_code = get_i16(buf)?; }
81 if version >= 0 { out.error_message = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
82 if version >= 0 { out.member_id = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
83 if version >= 0 { out.member_epoch = get_i32(buf)?; }
84 if version >= 0 { out.heartbeat_interval_ms = get_i32(buf)?; }
85 if version >= 0 { out.assignment = if get_i8(buf)? < 0 { None } else { Some(Assignment::decode(buf, version)?) }; }
86 if flex {
87 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
88 Ok(false)
89 })?;
90 }
91 Ok(out)
92 }
93}
94
95#[derive(Debug, Clone, PartialEq, Eq, Default)]
96pub struct Assignment {
97 pub topic_partitions: Vec<super::common::topic_partitions::TopicPartitions>,
98 pub unknown_tagged_fields: UnknownTaggedFields,
99}
100
101impl Encode for Assignment {
102 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
103 let flex = version >= 0;
104 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topic_partitions).len(), flex); for it in &self.topic_partitions { it.encode(buf, version)?; } } }
105 if flex {
106 let tagged = WriteTaggedFields::new();
107 tagged.write(buf, &self.unknown_tagged_fields);
108 }
109 Ok(())
110 }
111 fn encoded_len(&self, version: i16) -> usize {
112 let flex = version >= 0;
113 let mut n: usize = 0;
114 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topic_partitions).len(), flex); let body: usize = (self.topic_partitions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
115 if flex {
116 let known_pairs: Vec<(u32, usize)> = Vec::new();
117 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
118 }
119 n
120 }
121}
122
123impl<'de> Decode<'de> for Assignment {
124 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
125 let flex = version >= 0;
126 let mut out = Self::default();
127 if version >= 0 { out.topic_partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::topic_partitions::TopicPartitions::decode(buf, version)?); } v }; }
128 if flex {
129 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
130 Ok(false)
131 })?;
132 }
133 Ok(out)
134 }
135}
136
137#[must_use]
140#[allow(unused_comparisons)]
141pub fn default_json(version: i16) -> ::serde_json::Value {
142 let mut obj = ::serde_json::Map::new();
143 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
144 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
145 obj.insert("errorMessage".to_string(), ::serde_json::Value::Null);
146 obj.insert("memberId".to_string(), ::serde_json::Value::Null);
147 obj.insert("memberEpoch".to_string(), ::serde_json::json!(0));
148 obj.insert("heartbeatIntervalMs".to_string(), ::serde_json::json!(0));
149 obj.insert("assignment".to_string(), ::serde_json::Value::Null);
150 ::serde_json::Value::Object(obj)
151}