Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ShareGroupHeartbeatRequest.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i32, put_i32};
6use crate::primitives::string_bytes::{
7    compact_nullable_string_len, compact_string_len, nullable_string_len,
8    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
9    string_len,
10};
11use crate::primitives::string_bytes_borrowed::{
12    get_compact_nullable_string_borrowed, get_compact_string_borrowed,
13    get_nullable_string_borrowed, get_string_borrowed,
14};
15use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
16use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
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
23#[inline]
24fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
25
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct ShareGroupHeartbeatRequest<'a> {
28    pub group_id: &'a str,
29    pub member_id: &'a str,
30    pub member_epoch: i32,
31    pub rack_id: Option<&'a str>,
32    pub subscribed_topic_names: Option<Vec<&'a str>>,
33    pub unknown_tagged_fields: UnknownTaggedFields,
34}
35
36impl<'a> Default for ShareGroupHeartbeatRequest<'a> {
37    fn default() -> Self {
38        Self {
39            group_id: "",
40            member_id: "",
41            member_epoch: 0i32,
42            rack_id: None,
43            subscribed_topic_names: None,
44            unknown_tagged_fields: Default::default(),
45        }
46    }
47}
48
49impl<'a> ShareGroupHeartbeatRequest<'a> {
50    pub fn to_owned(&self) -> crate::owned::share_group_heartbeat_request::ShareGroupHeartbeatRequest {
51        crate::owned::share_group_heartbeat_request::ShareGroupHeartbeatRequest {
52            group_id: (self.group_id).to_string(),
53            member_id: (self.member_id).to_string(),
54            member_epoch: (self.member_epoch),
55            rack_id: (self.rack_id).map(|s| s.to_string()),
56            subscribed_topic_names: (self.subscribed_topic_names).as_ref().map(|v| v.iter().map(|s| s.to_string()).collect()),
57            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
58        }
59    }
60}
61
62impl<'a> Encode for ShareGroupHeartbeatRequest<'a> {
63    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
64        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
65            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
66        }
67        let flex = is_flexible(version);
68        if version >= 0 { if flex { put_compact_string(buf, self.group_id) } else { put_string(buf, self.group_id) } }
69        if version >= 0 { if flex { put_compact_string(buf, self.member_id) } else { put_string(buf, self.member_id) } }
70        if version >= 0 { put_i32(buf, self.member_epoch) }
71        if version >= 0 { if flex { put_compact_nullable_string(buf, self.rack_id) } else { put_nullable_string(buf, self.rack_id) } }
72        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) }; } } } }
73        if flex {
74            let tagged = WriteTaggedFields::new();
75            tagged.write(buf, &self.unknown_tagged_fields);
76        }
77        Ok(())
78    }
79    fn encoded_len(&self, version: i16) -> usize {
80        let flex = is_flexible(version);
81        let mut n: usize = 0;
82        if version >= 0 { n += if flex { compact_string_len(self.group_id) } else { string_len(self.group_id) }; }
83        if version >= 0 { n += if flex { compact_string_len(self.member_id) } else { string_len(self.member_id) }; }
84        if version >= 0 { n += 4; }
85        if version >= 0 { n += if flex { compact_nullable_string_len(self.rack_id) } else { nullable_string_len(self.rack_id) }; }
86        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 }; }
87        if flex {
88            let known_pairs: Vec<(u32, usize)> = Vec::new();
89            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
90        }
91        n
92    }
93}
94
95impl<'de> DecodeBorrow<'de> for ShareGroupHeartbeatRequest<'de> {
96    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
97        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
98            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
99        }
100        let flex = is_flexible(version);
101        let mut out = Self::default();
102        if version >= 0 { out.group_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
103        if version >= 0 { out.member_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
104        if version >= 0 { out.member_epoch = get_i32(buf)?; }
105        if version >= 0 { out.rack_id = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
106        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_borrowed(buf)? } else { get_string_borrowed(buf)? }); } Some(v) } } }; }
107        if flex {
108            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
109                Ok(false)
110            })?;
111        }
112        Ok(out)
113    }
114}