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