krabka_protocol/opt/rustwide/workdir/generated/
ConsumerGroupHeartbeatResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 fixed::{get_i8, get_i16, get_i32, put_i16, put_i32},
9 string_bytes::{
10 compact_nullable_string_len, get_compact_nullable_string_owned,
11 get_nullable_string_owned, nullable_string_len, put_compact_nullable_string,
12 put_nullable_string,
13 },
14 },
15 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
16};
17pub const API_KEY: i16 = 68;
18pub const MIN_VERSION: i16 = 0;
19pub const MAX_VERSION: i16 = 1;
20pub const FLEXIBLE_MIN: i16 = 0;
21#[inline]
22#[must_use]
23pub fn is_flexible(version: i16) -> bool {
24 version >= FLEXIBLE_MIN
25}
26#[derive(Debug, Clone, PartialEq, Eq, Default)]
27pub struct ConsumerGroupHeartbeatResponse {
28 pub throttle_time_ms: i32,
29 pub error_code: i16,
30 pub error_message: Option<String>,
31 pub member_id: Option<String>,
32 pub member_epoch: i32,
33 pub heartbeat_interval_ms: i32,
34 pub assignment: Option<Assignment>,
35 pub unknown_tagged_fields: UnknownTaggedFields,
36}
37impl Encode for ConsumerGroupHeartbeatResponse {
38 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
39 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
40 return Err(ProtocolError::UnsupportedVersion {
41 api_key: API_KEY,
42 version,
43 });
44 }
45 let flex = is_flexible(version);
46 if version >= 0 {
47 put_i32(buf, self.throttle_time_ms);
48 }
49 if version >= 0 {
50 put_i16(buf, self.error_code);
51 }
52 if version >= 0 {
53 if flex {
54 let () = put_compact_nullable_string(buf, self.error_message.as_deref());
55 } else {
56 let () = put_nullable_string(buf, self.error_message.as_deref());
57 }
58 }
59 if version >= 0 {
60 if flex {
61 let () = put_compact_nullable_string(buf, self.member_id.as_deref());
62 } else {
63 let () = put_nullable_string(buf, self.member_id.as_deref());
64 }
65 }
66 if version >= 0 {
67 put_i32(buf, self.member_epoch);
68 }
69 if version >= 0 {
70 put_i32(buf, self.heartbeat_interval_ms);
71 }
72 if version >= 0 {
73 match &self.assignment {
74 None => {
75 buf.put_i8(-1);
76 }
77 Some(v) => {
78 buf.put_i8(1);
79 v.encode(buf, version)?;
80 }
81 }
82 }
83 if flex {
84 let tagged = WriteTaggedFields::new();
85 tagged.write(buf, &self.unknown_tagged_fields);
86 }
87 Ok(())
88 }
89 fn encoded_len(&self, version: i16) -> usize {
90 let flex = is_flexible(version);
91 let mut n: usize = 0;
92 if version >= 0 {
93 n += 4;
94 }
95 if version >= 0 {
96 n += 2;
97 }
98 if version >= 0 {
99 n += if flex {
100 compact_nullable_string_len(self.error_message.as_deref())
101 } else {
102 nullable_string_len(self.error_message.as_deref())
103 };
104 }
105 if version >= 0 {
106 n += if flex {
107 compact_nullable_string_len(self.member_id.as_deref())
108 } else {
109 nullable_string_len(self.member_id.as_deref())
110 };
111 }
112 if version >= 0 {
113 n += 4;
114 }
115 if version >= 0 {
116 n += 4;
117 }
118 if version >= 0 {
119 n += 1 + self
120 .assignment
121 .as_ref()
122 .map_or(0, |v| v.encoded_len(version));
123 }
124 if flex {
125 let known_pairs: Vec<(u32, usize)> = Vec::new();
126 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
127 }
128 n
129 }
130}
131impl Decode<'_> for ConsumerGroupHeartbeatResponse {
132 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
133 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
134 return Err(ProtocolError::UnsupportedVersion {
135 api_key: API_KEY,
136 version,
137 });
138 }
139 let flex = is_flexible(version);
140 let mut out = Self::default();
141 if version >= 0 {
142 out.throttle_time_ms = get_i32(buf)?;
143 }
144 if version >= 0 {
145 out.error_code = get_i16(buf)?;
146 }
147 if version >= 0 {
148 out.error_message = if flex {
149 get_compact_nullable_string_owned(buf)?
150 } else {
151 get_nullable_string_owned(buf)?
152 };
153 }
154 if version >= 0 {
155 out.member_id = if flex {
156 get_compact_nullable_string_owned(buf)?
157 } else {
158 get_nullable_string_owned(buf)?
159 };
160 }
161 if version >= 0 {
162 out.member_epoch = get_i32(buf)?;
163 }
164 if version >= 0 {
165 out.heartbeat_interval_ms = get_i32(buf)?;
166 }
167 if version >= 0 {
168 out.assignment = if get_i8(buf)? < 0 {
169 None
170 } else {
171 Some(Assignment::decode(buf, version)?)
172 };
173 }
174 if flex {
175 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
176 }
177 Ok(out)
178 }
179}
180#[cfg(test)]
181impl ConsumerGroupHeartbeatResponse {
182 #[must_use]
183 pub fn populated(version: i16) -> Self {
184 let mut m = Self::default();
185 if version >= 0 {
186 m.throttle_time_ms = 1i32;
187 }
188 if version >= 0 {
189 m.error_code = 1i16;
190 }
191 if version >= 0 {
192 m.error_message = Some("x".to_string());
193 }
194 if version >= 0 {
195 m.member_id = Some("x".to_string());
196 }
197 if version >= 0 {
198 m.member_epoch = 1i32;
199 }
200 if version >= 0 {
201 m.heartbeat_interval_ms = 1i32;
202 }
203 if version >= 0 {
204 m.assignment = Some(Assignment::populated(version));
205 }
206 m
207 }
208}
209#[derive(Debug, Clone, PartialEq, Eq, Default)]
210pub struct Assignment {
211 pub topic_partitions:
212 Vec<super::common::consumer_group_heartbeat_response::topic_partitions::TopicPartitions>,
213 pub unknown_tagged_fields: UnknownTaggedFields,
214}
215impl Encode for Assignment {
216 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
217 let flex = version >= 0;
218 if version >= 0 {
219 {
220 crate::primitives::array::put_array_len(buf, (self.topic_partitions).len(), flex);
221 for it in &self.topic_partitions {
222 it.encode(buf, version)?;
223 }
224 };
225 }
226 if flex {
227 let tagged = WriteTaggedFields::new();
228 tagged.write(buf, &self.unknown_tagged_fields);
229 }
230 Ok(())
231 }
232 fn encoded_len(&self, version: i16) -> usize {
233 let flex = version >= 0;
234 let mut n: usize = 0;
235 if version >= 0 {
236 n += {
237 let prefix = crate::primitives::array::array_len_prefix_len(
238 (self.topic_partitions).len(),
239 flex,
240 );
241 let body: usize = (self.topic_partitions)
242 .iter()
243 .map(|it| it.encoded_len(version))
244 .sum();
245 prefix + body
246 };
247 }
248 if flex {
249 let known_pairs: Vec<(u32, usize)> = Vec::new();
250 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
251 }
252 n
253 }
254}
255impl Decode<'_> for Assignment {
256 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
257 let flex = version >= 0;
258 let mut out = Self::default();
259 if version >= 0 {
260 out.topic_partitions = {
261 let n = crate::primitives::array::get_array_len(buf, flex)?;
262 let mut v = Vec::with_capacity(n);
263 for _ in 0..n {
264 v.push(super::common::consumer_group_heartbeat_response::topic_partitions::TopicPartitions::decode(buf, version)?);
265 }
266 v
267 };
268 }
269 if flex {
270 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
271 }
272 Ok(out)
273 }
274}
275#[cfg(test)]
276impl Assignment {
277 #[must_use]
278 pub fn populated(version: i16) -> Self {
279 let mut m = Self::default();
280 if version >= 0 {
281 m.topic_partitions = vec![super::common::consumer_group_heartbeat_response::topic_partitions::TopicPartitions::populated(version)];
282 }
283 m
284 }
285}
286#[must_use]
289#[allow(unused_comparisons)]
290pub fn default_json(_version: i16) -> ::serde_json::Value {
291 let mut obj = ::serde_json::Map::new();
292 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
293 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
294 obj.insert("errorMessage".to_string(), ::serde_json::Value::Null);
295 obj.insert("memberId".to_string(), ::serde_json::Value::Null);
296 obj.insert("memberEpoch".to_string(), ::serde_json::json!(0));
297 obj.insert("heartbeatIntervalMs".to_string(), ::serde_json::json!(0));
298 obj.insert("assignment".to_string(), ::serde_json::Value::Null);
299 ::serde_json::Value::Object(obj)
300}