Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{get_i32, put_i32};
4use crate::primitives::string_bytes::{
5    compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
6    get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
7    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
8};
9use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
10use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
11use bytes::{Buf, BufMut};
12pub const API_KEY: i16 = 68;
13pub const MIN_VERSION: i16 = 0;
14pub const MAX_VERSION: i16 = 1;
15pub const FLEXIBLE_MIN: i16 = 0;
16#[inline]
17fn is_flexible(version: i16) -> bool {
18    version >= FLEXIBLE_MIN
19}
20#[derive(Debug, Clone, PartialEq, Eq)]
21pub struct ConsumerGroupHeartbeatRequest {
22    pub group_id: String,
23    pub member_id: String,
24    pub member_epoch: i32,
25    pub instance_id: Option<String>,
26    pub rack_id: Option<String>,
27    pub rebalance_timeout_ms: i32,
28    pub subscribed_topic_names: Option<Vec<String>>,
29    pub subscribed_topic_regex: Option<String>,
30    pub server_assignor: Option<String>,
31    pub topic_partitions: Option<Vec<TopicPartitions>>,
32    pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Default for ConsumerGroupHeartbeatRequest {
35    fn default() -> Self {
36        Self {
37            group_id: String::new(),
38            member_id: String::new(),
39            member_epoch: 0i32,
40            instance_id: None,
41            rack_id: None,
42            rebalance_timeout_ms: -1i32,
43            subscribed_topic_names: None,
44            subscribed_topic_regex: None,
45            server_assignor: None,
46            topic_partitions: None,
47            unknown_tagged_fields: Default::default(),
48        }
49    }
50}
51impl Encode for ConsumerGroupHeartbeatRequest {
52    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
53        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
54            return Err(ProtocolError::UnsupportedVersion {
55                api_key: API_KEY,
56                version,
57            });
58        }
59        let flex = is_flexible(version);
60        if version >= 0 {
61            if flex {
62                put_compact_string(buf, &self.group_id);
63            } else {
64                put_string(buf, &self.group_id);
65            }
66        }
67        if version >= 0 {
68            if flex {
69                put_compact_string(buf, &self.member_id);
70            } else {
71                put_string(buf, &self.member_id);
72            }
73        }
74        if version >= 0 {
75            put_i32(buf, self.member_epoch);
76        }
77        if version >= 0 {
78            if flex {
79                put_compact_nullable_string(buf, self.instance_id.as_deref());
80            } else {
81                put_nullable_string(buf, self.instance_id.as_deref());
82            }
83        }
84        if version >= 0 {
85            if flex {
86                put_compact_nullable_string(buf, self.rack_id.as_deref());
87            } else {
88                put_nullable_string(buf, self.rack_id.as_deref());
89            }
90        }
91        if version >= 0 {
92            put_i32(buf, self.rebalance_timeout_ms);
93        }
94        if version >= 0 {
95            {
96                let len = (self.subscribed_topic_names).as_ref().map(Vec::len);
97                crate::primitives::array::put_nullable_array_len(buf, len, flex);
98                if let Some(v) = &self.subscribed_topic_names {
99                    for it in v {
100                        if flex {
101                            put_compact_string(buf, it);
102                        } else {
103                            put_string(buf, it);
104                        }
105                    }
106                }
107            }
108        }
109        if version >= 1 {
110            if flex {
111                put_compact_nullable_string(buf, self.subscribed_topic_regex.as_deref());
112            } else {
113                put_nullable_string(buf, self.subscribed_topic_regex.as_deref());
114            }
115        }
116        if version >= 0 {
117            if flex {
118                put_compact_nullable_string(buf, self.server_assignor.as_deref());
119            } else {
120                put_nullable_string(buf, self.server_assignor.as_deref());
121            }
122        }
123        if version >= 0 {
124            {
125                let len = (self.topic_partitions).as_ref().map(Vec::len);
126                crate::primitives::array::put_nullable_array_len(buf, len, flex);
127                if let Some(v) = &self.topic_partitions {
128                    for it in v {
129                        it.encode(buf, version)?;
130                    }
131                }
132            }
133        }
134        if flex {
135            let tagged = WriteTaggedFields::new();
136            tagged.write(buf, &self.unknown_tagged_fields);
137        }
138        Ok(())
139    }
140    fn encoded_len(&self, version: i16) -> usize {
141        let flex = is_flexible(version);
142        let mut n: usize = 0;
143        if version >= 0 {
144            n += if flex {
145                compact_string_len(&self.group_id)
146            } else {
147                string_len(&self.group_id)
148            };
149        }
150        if version >= 0 {
151            n += if flex {
152                compact_string_len(&self.member_id)
153            } else {
154                string_len(&self.member_id)
155            };
156        }
157        if version >= 0 {
158            n += 4;
159        }
160        if version >= 0 {
161            n += if flex {
162                compact_nullable_string_len(self.instance_id.as_deref())
163            } else {
164                nullable_string_len(self.instance_id.as_deref())
165            };
166        }
167        if version >= 0 {
168            n += if flex {
169                compact_nullable_string_len(self.rack_id.as_deref())
170            } else {
171                nullable_string_len(self.rack_id.as_deref())
172            };
173        }
174        if version >= 0 {
175            n += 4;
176        }
177        if version >= 0 {
178            n += {
179                let opt: Option<&Vec<_>> = (self.subscribed_topic_names).as_ref();
180                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
181                    opt.map(std::vec::Vec::len),
182                    flex,
183                );
184                let body: usize = opt.map_or(0, |v| {
185                    v.iter()
186                        .map(|it| {
187                            if flex {
188                                compact_string_len(it)
189                            } else {
190                                string_len(it)
191                            }
192                        })
193                        .sum()
194                });
195                prefix + body
196            };
197        }
198        if version >= 1 {
199            n += if flex {
200                compact_nullable_string_len(self.subscribed_topic_regex.as_deref())
201            } else {
202                nullable_string_len(self.subscribed_topic_regex.as_deref())
203            };
204        }
205        if version >= 0 {
206            n += if flex {
207                compact_nullable_string_len(self.server_assignor.as_deref())
208            } else {
209                nullable_string_len(self.server_assignor.as_deref())
210            };
211        }
212        if version >= 0 {
213            n += {
214                let opt: Option<&Vec<_>> = (self.topic_partitions).as_ref();
215                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
216                    opt.map(std::vec::Vec::len),
217                    flex,
218                );
219                let body: usize =
220                    opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
221                prefix + body
222            };
223        }
224        if flex {
225            let known_pairs: Vec<(u32, usize)> = Vec::new();
226            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
227        }
228        n
229    }
230}
231impl Decode<'_> for ConsumerGroupHeartbeatRequest {
232    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
233        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
234            return Err(ProtocolError::UnsupportedVersion {
235                api_key: API_KEY,
236                version,
237            });
238        }
239        let flex = is_flexible(version);
240        let mut out = Self::default();
241        if version >= 0 {
242            out.group_id = if flex {
243                get_compact_string_owned(buf)?
244            } else {
245                get_string_owned(buf)?
246            };
247        }
248        if version >= 0 {
249            out.member_id = if flex {
250                get_compact_string_owned(buf)?
251            } else {
252                get_string_owned(buf)?
253            };
254        }
255        if version >= 0 {
256            out.member_epoch = get_i32(buf)?;
257        }
258        if version >= 0 {
259            out.instance_id = if flex {
260                get_compact_nullable_string_owned(buf)?
261            } else {
262                get_nullable_string_owned(buf)?
263            };
264        }
265        if version >= 0 {
266            out.rack_id = if flex {
267                get_compact_nullable_string_owned(buf)?
268            } else {
269                get_nullable_string_owned(buf)?
270            };
271        }
272        if version >= 0 {
273            out.rebalance_timeout_ms = get_i32(buf)?;
274        }
275        if version >= 0 {
276            out.subscribed_topic_names = {
277                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
278                match opt {
279                    None => None,
280                    Some(n) => {
281                        let mut v = Vec::with_capacity(n);
282                        for _ in 0..n {
283                            v.push(if flex {
284                                get_compact_string_owned(buf)?
285                            } else {
286                                get_string_owned(buf)?
287                            });
288                        }
289                        Some(v)
290                    }
291                }
292            };
293        }
294        if version >= 1 {
295            out.subscribed_topic_regex = if flex {
296                get_compact_nullable_string_owned(buf)?
297            } else {
298                get_nullable_string_owned(buf)?
299            };
300        }
301        if version >= 0 {
302            out.server_assignor = if flex {
303                get_compact_nullable_string_owned(buf)?
304            } else {
305                get_nullable_string_owned(buf)?
306            };
307        }
308        if version >= 0 {
309            out.topic_partitions = {
310                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
311                match opt {
312                    None => None,
313                    Some(n) => {
314                        let mut v = Vec::with_capacity(n);
315                        for _ in 0..n {
316                            v.push(TopicPartitions::decode(buf, version)?);
317                        }
318                        Some(v)
319                    }
320                }
321            };
322        }
323        if flex {
324            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
325        }
326        Ok(out)
327    }
328}
329#[cfg(test)]
330impl ConsumerGroupHeartbeatRequest {
331    #[must_use]
332    pub fn populated(version: i16) -> Self {
333        let mut m = Self::default();
334        if version >= 0 {
335            m.group_id = "x".to_string();
336        }
337        if version >= 0 {
338            m.member_id = "x".to_string();
339        }
340        if version >= 0 {
341            m.member_epoch = 1i32;
342        }
343        if version >= 0 {
344            m.instance_id = Some("x".to_string());
345        }
346        if version >= 0 {
347            m.rack_id = Some("x".to_string());
348        }
349        if version >= 0 {
350            m.rebalance_timeout_ms = 1i32;
351        }
352        if version >= 0 {
353            m.subscribed_topic_names = Some(vec!["x".to_string()]);
354        }
355        if version >= 1 {
356            m.subscribed_topic_regex = Some("x".to_string());
357        }
358        if version >= 0 {
359            m.server_assignor = Some("x".to_string());
360        }
361        if version >= 0 {
362            m.topic_partitions = Some(vec![TopicPartitions::populated(version)]);
363        }
364        m
365    }
366}
367#[derive(Debug, Clone, PartialEq, Eq, Default)]
368pub struct TopicPartitions {
369    pub topic_id: crate::primitives::uuid::Uuid,
370    pub partitions: Vec<i32>,
371    pub unknown_tagged_fields: UnknownTaggedFields,
372}
373impl Encode for TopicPartitions {
374    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
375        let flex = version >= 0;
376        if version >= 0 {
377            crate::primitives::uuid::put_uuid(buf, self.topic_id);
378        }
379        if version >= 0 {
380            {
381                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
382                for it in &self.partitions {
383                    put_i32(buf, *it);
384                }
385            }
386        }
387        if flex {
388            let tagged = WriteTaggedFields::new();
389            tagged.write(buf, &self.unknown_tagged_fields);
390        }
391        Ok(())
392    }
393    fn encoded_len(&self, version: i16) -> usize {
394        let flex = version >= 0;
395        let mut n: usize = 0;
396        if version >= 0 {
397            n += 16;
398        }
399        if version >= 0 {
400            n += {
401                let prefix =
402                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
403                let body: usize = (self.partitions).iter().map(|_| 4).sum();
404                prefix + body
405            };
406        }
407        if flex {
408            let known_pairs: Vec<(u32, usize)> = Vec::new();
409            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
410        }
411        n
412    }
413}
414impl Decode<'_> for TopicPartitions {
415    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
416        let flex = version >= 0;
417        let mut out = Self::default();
418        if version >= 0 {
419            out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
420        }
421        if version >= 0 {
422            out.partitions = {
423                let n = crate::primitives::array::get_array_len(buf, flex)?;
424                let mut v = Vec::with_capacity(n);
425                for _ in 0..n {
426                    v.push(get_i32(buf)?);
427                }
428                v
429            };
430        }
431        if flex {
432            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
433        }
434        Ok(out)
435    }
436}
437#[cfg(test)]
438impl TopicPartitions {
439    #[must_use]
440    pub fn populated(version: i16) -> Self {
441        let mut m = Self::default();
442        if version >= 0 {
443            m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
444        }
445        if version >= 0 {
446            m.partitions = vec![1i32];
447        }
448        m
449    }
450}
451/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
452/// Only includes fields valid for the given version.
453#[must_use]
454#[allow(unused_comparisons)]
455pub fn default_json(version: i16) -> ::serde_json::Value {
456    let mut obj = ::serde_json::Map::new();
457    obj.insert(
458        "groupId".to_string(),
459        ::serde_json::Value::String(String::new()),
460    );
461    obj.insert(
462        "memberId".to_string(),
463        ::serde_json::Value::String(String::new()),
464    );
465    obj.insert("memberEpoch".to_string(), ::serde_json::json!(0));
466    obj.insert("instanceId".to_string(), ::serde_json::Value::Null);
467    obj.insert("rackId".to_string(), ::serde_json::Value::Null);
468    obj.insert("rebalanceTimeoutMs".to_string(), ::serde_json::json!(-1));
469    obj.insert(
470        "subscribedTopicNames".to_string(),
471        ::serde_json::Value::Null,
472    );
473    if version >= 1 {
474        obj.insert(
475            "subscribedTopicRegex".to_string(),
476            ::serde_json::Value::Null,
477        );
478    }
479    obj.insert("serverAssignor".to_string(), ::serde_json::Value::Null);
480    obj.insert("topicPartitions".to_string(), ::serde_json::Value::Null);
481    ::serde_json::Value::Object(obj)
482}
483impl crate::ProtocolRequest for ConsumerGroupHeartbeatRequest {
484    const API_KEY: i16 = API_KEY;
485    const MIN_VERSION: i16 = MIN_VERSION;
486    const MAX_VERSION: i16 = MAX_VERSION;
487    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
488    type Response = super::consumer_group_heartbeat_response::ConsumerGroupHeartbeatResponse;
489}