Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ShareGroupHeartbeatResponse.owned.rs

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