Skip to main content

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