Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ShareGroupHeartbeatRequest.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_i32, put_i32};
6use crate::primitives::string_bytes::{
7    compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8    get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
10    string_len,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 76;
16pub const MIN_VERSION: i16 = 1;
17pub const MAX_VERSION: i16 = 1;
18pub const FLEXIBLE_MIN: i16 = 0;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct ShareGroupHeartbeatRequest {
25    pub group_id: String,
26    pub member_id: String,
27    pub member_epoch: i32,
28    pub rack_id: Option<String>,
29    pub subscribed_topic_names: Option<Vec<String>>,
30    pub unknown_tagged_fields: UnknownTaggedFields,
31}
32
33impl Encode for ShareGroupHeartbeatRequest {
34    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
35        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
36            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
37        }
38        let flex = is_flexible(version);
39        if version >= 0 { if flex { put_compact_string(buf, &self.group_id) } else { put_string(buf, &self.group_id) } }
40        if version >= 0 { if flex { put_compact_string(buf, &self.member_id) } else { put_string(buf, &self.member_id) } }
41        if version >= 0 { put_i32(buf, self.member_epoch) }
42        if version >= 0 { if flex { put_compact_nullable_string(buf, self.rack_id.as_deref()) } else { put_nullable_string(buf, self.rack_id.as_deref()) } }
43        if version >= 0 { { let len = (self.subscribed_topic_names).as_ref().map(Vec::len); crate::primitives::array::put_nullable_array_len(buf, len, flex); if let Some(v) = &self.subscribed_topic_names { for it in v { if flex { put_compact_string(buf, &*it) } else { put_string(buf, &*it) }; } } } }
44        if flex {
45            let tagged = WriteTaggedFields::new();
46            tagged.write(buf, &self.unknown_tagged_fields);
47        }
48        Ok(())
49    }
50    fn encoded_len(&self, version: i16) -> usize {
51        let flex = is_flexible(version);
52        let mut n: usize = 0;
53        if version >= 0 { n += if flex { compact_string_len(&self.group_id) } else { string_len(&self.group_id) }; }
54        if version >= 0 { n += if flex { compact_string_len(&self.member_id) } else { string_len(&self.member_id) }; }
55        if version >= 0 { n += 4; }
56        if version >= 0 { n += if flex { compact_nullable_string_len(self.rack_id.as_deref()) } else { nullable_string_len(self.rack_id.as_deref()) }; }
57        if version >= 0 { n += { let opt: Option<&Vec<_>> = (self.subscribed_topic_names).as_ref(); let prefix = crate::primitives::array::nullable_array_len_prefix_len(opt.map(|v| v.len()), flex); let body: usize = opt.map_or(0, |v| v.iter().map(|it| if flex { compact_string_len(&*it) } else { string_len(&*it) }).sum()); prefix + body }; }
58        if flex {
59            let known_pairs: Vec<(u32, usize)> = Vec::new();
60            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
61        }
62        n
63    }
64}
65
66impl<'de> Decode<'de> for ShareGroupHeartbeatRequest {
67    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
68        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
69            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
70        }
71        let flex = is_flexible(version);
72        let mut out = Self::default();
73        if version >= 0 { out.group_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
74        if version >= 0 { out.member_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
75        if version >= 0 { out.member_epoch = get_i32(buf)?; }
76        if version >= 0 { out.rack_id = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
77        if version >= 0 { out.subscribed_topic_names = { let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?; match opt { None => None, Some(n) => { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }); } Some(v) } } }; }
78        if flex {
79            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
80                Ok(false)
81            })?;
82        }
83        Ok(out)
84    }
85}
86
87/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
88/// Only includes fields valid for the given version.
89#[must_use]
90#[allow(unused_comparisons)]
91pub fn default_json(version: i16) -> ::serde_json::Value {
92    let mut obj = ::serde_json::Map::new();
93    obj.insert("groupId".to_string(), ::serde_json::Value::String(String::new()));
94    obj.insert("memberId".to_string(), ::serde_json::Value::String(String::new()));
95    obj.insert("memberEpoch".to_string(), ::serde_json::json!(0));
96    obj.insert("rackId".to_string(), ::serde_json::Value::Null);
97    obj.insert("subscribedTopicNames".to_string(), ::serde_json::Value::Null);
98    ::serde_json::Value::Object(obj)
99}
100
101impl crate::ProtocolRequest for ShareGroupHeartbeatRequest {
102    const API_KEY: i16 = API_KEY;
103    const MIN_VERSION: i16 = MIN_VERSION;
104    const MAX_VERSION: i16 = MAX_VERSION;
105    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
106    type Response = super::share_group_heartbeat_response::ShareGroupHeartbeatResponse;
107}