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