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