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