Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{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::primitives::string_bytes::{put_bytes, put_compact_bytes};
16use crate::primitives::string_bytes_borrowed::{get_bytes_borrowed, get_compact_bytes_borrowed};
17use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
18use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
19
20pub const API_KEY: i16 = 11;
21pub const MIN_VERSION: i16 = 0;
22pub const MAX_VERSION: i16 = 9;
23pub const FLEXIBLE_MIN: i16 = 6;
24
25#[inline]
26fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
27
28#[derive(Debug, Clone, PartialEq, Eq)]
29pub struct JoinGroupRequest<'a> {
30    pub group_id: &'a str,
31    pub session_timeout_ms: i32,
32    pub rebalance_timeout_ms: i32,
33    pub member_id: &'a str,
34    pub group_instance_id: Option<&'a str>,
35    pub protocol_type: &'a str,
36    pub protocols: Vec<JoinGroupRequestProtocol<'a>>,
37    pub reason: Option<&'a str>,
38    pub unknown_tagged_fields: UnknownTaggedFields,
39}
40
41impl<'a> Default for JoinGroupRequest<'a> {
42    fn default() -> Self {
43        Self {
44            group_id: "",
45            session_timeout_ms: 0i32,
46            rebalance_timeout_ms: -1i32,
47            member_id: "",
48            group_instance_id: None,
49            protocol_type: "",
50            protocols: Vec::new(),
51            reason: None,
52            unknown_tagged_fields: Default::default(),
53        }
54    }
55}
56
57impl<'a> JoinGroupRequest<'a> {
58    pub fn to_owned(&self) -> crate::owned::join_group_request::JoinGroupRequest {
59        crate::owned::join_group_request::JoinGroupRequest {
60            group_id: (self.group_id).to_string(),
61            session_timeout_ms: (self.session_timeout_ms),
62            rebalance_timeout_ms: (self.rebalance_timeout_ms),
63            member_id: (self.member_id).to_string(),
64            group_instance_id: (self.group_instance_id).map(|s| s.to_string()),
65            protocol_type: (self.protocol_type).to_string(),
66            protocols: (self.protocols).iter().map(|it| it.to_owned()).collect(),
67            reason: (self.reason).map(|s| s.to_string()),
68            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
69        }
70    }
71}
72
73impl<'a> Encode for JoinGroupRequest<'a> {
74    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
75        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
76            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
77        }
78        let flex = is_flexible(version);
79        if version >= 0 { if flex { put_compact_string(buf, self.group_id) } else { put_string(buf, self.group_id) } }
80        if version >= 0 { put_i32(buf, self.session_timeout_ms) }
81        if version >= 1 { put_i32(buf, self.rebalance_timeout_ms) }
82        if version >= 0 { if flex { put_compact_string(buf, self.member_id) } else { put_string(buf, self.member_id) } }
83        if version >= 5 { if flex { put_compact_nullable_string(buf, self.group_instance_id) } else { put_nullable_string(buf, self.group_instance_id) } }
84        if version >= 0 { if flex { put_compact_string(buf, self.protocol_type) } else { put_string(buf, self.protocol_type) } }
85        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.protocols).len(), flex); for it in &self.protocols { it.encode(buf, version)?; } } }
86        if version >= 8 { if flex { put_compact_nullable_string(buf, self.reason) } else { put_nullable_string(buf, self.reason) } }
87        if flex {
88            let tagged = WriteTaggedFields::new();
89            tagged.write(buf, &self.unknown_tagged_fields);
90        }
91        Ok(())
92    }
93    fn encoded_len(&self, version: i16) -> usize {
94        let flex = is_flexible(version);
95        let mut n: usize = 0;
96        if version >= 0 { n += if flex { compact_string_len(self.group_id) } else { string_len(self.group_id) }; }
97        if version >= 0 { n += 4; }
98        if version >= 1 { n += 4; }
99        if version >= 0 { n += if flex { compact_string_len(self.member_id) } else { string_len(self.member_id) }; }
100        if version >= 5 { n += if flex { compact_nullable_string_len(self.group_instance_id) } else { nullable_string_len(self.group_instance_id) }; }
101        if version >= 0 { n += if flex { compact_string_len(self.protocol_type) } else { string_len(self.protocol_type) }; }
102        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.protocols).len(), flex); let body: usize = (self.protocols).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
103        if version >= 8 { n += if flex { compact_nullable_string_len(self.reason) } else { nullable_string_len(self.reason) }; }
104        if flex {
105            let known_pairs: Vec<(u32, usize)> = Vec::new();
106            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
107        }
108        n
109    }
110}
111
112impl<'de> DecodeBorrow<'de> for JoinGroupRequest<'de> {
113    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
114        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
115            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
116        }
117        let flex = is_flexible(version);
118        let mut out = Self::default();
119        if version >= 0 { out.group_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
120        if version >= 0 { out.session_timeout_ms = get_i32(buf)?; }
121        if version >= 1 { out.rebalance_timeout_ms = get_i32(buf)?; }
122        if version >= 0 { out.member_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
123        if version >= 5 { out.group_instance_id = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
124        if version >= 0 { out.protocol_type = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
125        if version >= 0 { out.protocols = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(JoinGroupRequestProtocol::decode_borrow(buf, version)?); } v }; }
126        if version >= 8 { out.reason = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
127        if flex {
128            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
129                Ok(false)
130            })?;
131        }
132        Ok(out)
133    }
134}
135
136#[derive(Debug, Clone, PartialEq, Eq)]
137pub struct JoinGroupRequestProtocol<'a> {
138    pub name: &'a str,
139    pub metadata: &'a [u8],
140    pub unknown_tagged_fields: UnknownTaggedFields,
141}
142
143impl<'a> Default for JoinGroupRequestProtocol<'a> {
144    fn default() -> Self {
145        Self {
146            name: "",
147            metadata: &[],
148            unknown_tagged_fields: Default::default(),
149        }
150    }
151}
152
153impl<'a> JoinGroupRequestProtocol<'a> {
154    pub fn to_owned(&self) -> crate::owned::join_group_request::JoinGroupRequestProtocol {
155        crate::owned::join_group_request::JoinGroupRequestProtocol {
156            name: (self.name).to_string(),
157            metadata: Bytes::copy_from_slice(self.metadata),
158            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
159        }
160    }
161}
162
163impl<'a> Encode for JoinGroupRequestProtocol<'a> {
164    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
165        let flex = version >= 6;
166        if version >= 0 { if flex { put_compact_string(buf, self.name) } else { put_string(buf, self.name) } }
167        if version >= 0 { if flex { put_compact_bytes(buf, self.metadata) } else { put_bytes(buf, self.metadata) } }
168        if flex {
169            let tagged = WriteTaggedFields::new();
170            tagged.write(buf, &self.unknown_tagged_fields);
171        }
172        Ok(())
173    }
174    fn encoded_len(&self, version: i16) -> usize {
175        let flex = version >= 6;
176        let mut n: usize = 0;
177        if version >= 0 { n += if flex { compact_string_len(self.name) } else { string_len(self.name) }; }
178        if version >= 0 { n += if flex { crate::primitives::varint::uvarint_len(u32::try_from((self.metadata).len() + 1).unwrap()) + (self.metadata).len() } else { 4 + (self.metadata).len() }; }
179        if flex {
180            let known_pairs: Vec<(u32, usize)> = Vec::new();
181            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
182        }
183        n
184    }
185}
186
187impl<'de> DecodeBorrow<'de> for JoinGroupRequestProtocol<'de> {
188    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
189        let flex = version >= 6;
190        let mut out = Self::default();
191        if version >= 0 { out.name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
192        if version >= 0 { out.metadata = if flex { get_compact_bytes_borrowed(buf)? } else { get_bytes_borrowed(buf)? }; }
193        if flex {
194            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
195                Ok(false)
196            })?;
197        }
198        Ok(out)
199    }
200}