Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
ShareGroupHeartbeatResponse.borrowed.rs

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