Skip to main content

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

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