Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AlterShareGroupOffsetsRequest.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, get_i64, put_i32, put_i64};
6use crate::primitives::string_bytes::{
7    compact_string_len, put_compact_string, put_string, string_len,
8};
9use crate::primitives::string_bytes_borrowed::{
10    get_compact_string_borrowed, get_string_borrowed,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 91;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 0;
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)]
24pub struct AlterShareGroupOffsetsRequest<'a> {
25    pub group_id: &'a str,
26    pub topics: Vec<AlterShareGroupOffsetsRequestTopic<'a>>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29
30impl<'a> Default for AlterShareGroupOffsetsRequest<'a> {
31    fn default() -> Self {
32        Self {
33            group_id: "",
34            topics: Vec::new(),
35            unknown_tagged_fields: Default::default(),
36        }
37    }
38}
39
40impl<'a> AlterShareGroupOffsetsRequest<'a> {
41    pub fn to_owned(&self) -> crate::owned::alter_share_group_offsets_request::AlterShareGroupOffsetsRequest {
42        crate::owned::alter_share_group_offsets_request::AlterShareGroupOffsetsRequest {
43            group_id: (self.group_id).to_string(),
44            topics: (self.topics).iter().map(|it| it.to_owned()).collect(),
45            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
46        }
47    }
48}
49
50impl<'a> Encode for AlterShareGroupOffsetsRequest<'a> {
51    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
52        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
53            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
54        }
55        let flex = is_flexible(version);
56        if version >= 0 { if flex { put_compact_string(buf, self.group_id) } else { put_string(buf, self.group_id) } }
57        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
58        if flex {
59            let tagged = WriteTaggedFields::new();
60            tagged.write(buf, &self.unknown_tagged_fields);
61        }
62        Ok(())
63    }
64    fn encoded_len(&self, version: i16) -> usize {
65        let flex = is_flexible(version);
66        let mut n: usize = 0;
67        if version >= 0 { n += if flex { compact_string_len(self.group_id) } else { string_len(self.group_id) }; }
68        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topics).len(), flex); let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
69        if flex {
70            let known_pairs: Vec<(u32, usize)> = Vec::new();
71            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
72        }
73        n
74    }
75}
76
77impl<'de> DecodeBorrow<'de> for AlterShareGroupOffsetsRequest<'de> {
78    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
79        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
80            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
81        }
82        let flex = is_flexible(version);
83        let mut out = Self::default();
84        if version >= 0 { out.group_id = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
85        if version >= 0 { out.topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(AlterShareGroupOffsetsRequestTopic::decode_borrow(buf, version)?); } v }; }
86        if flex {
87            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
88                Ok(false)
89            })?;
90        }
91        Ok(out)
92    }
93}
94
95#[derive(Debug, Clone, PartialEq, Eq)]
96pub struct AlterShareGroupOffsetsRequestTopic<'a> {
97    pub topic_name: &'a str,
98    pub partitions: Vec<AlterShareGroupOffsetsRequestPartition>,
99    pub unknown_tagged_fields: UnknownTaggedFields,
100}
101
102impl<'a> Default for AlterShareGroupOffsetsRequestTopic<'a> {
103    fn default() -> Self {
104        Self {
105            topic_name: "",
106            partitions: Vec::new(),
107            unknown_tagged_fields: Default::default(),
108        }
109    }
110}
111
112impl<'a> AlterShareGroupOffsetsRequestTopic<'a> {
113    pub fn to_owned(&self) -> crate::owned::alter_share_group_offsets_request::AlterShareGroupOffsetsRequestTopic {
114        crate::owned::alter_share_group_offsets_request::AlterShareGroupOffsetsRequestTopic {
115            topic_name: (self.topic_name).to_string(),
116            partitions: (self.partitions).iter().map(|it| it.to_owned()).collect(),
117            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
118        }
119    }
120}
121
122impl<'a> Encode for AlterShareGroupOffsetsRequestTopic<'a> {
123    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
124        let flex = version >= 0;
125        if version >= 0 { if flex { put_compact_string(buf, self.topic_name) } else { put_string(buf, self.topic_name) } }
126        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
127        if flex {
128            let tagged = WriteTaggedFields::new();
129            tagged.write(buf, &self.unknown_tagged_fields);
130        }
131        Ok(())
132    }
133    fn encoded_len(&self, version: i16) -> usize {
134        let flex = version >= 0;
135        let mut n: usize = 0;
136        if version >= 0 { n += if flex { compact_string_len(self.topic_name) } else { string_len(self.topic_name) }; }
137        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex); let body: usize = (self.partitions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
138        if flex {
139            let known_pairs: Vec<(u32, usize)> = Vec::new();
140            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
141        }
142        n
143    }
144}
145
146impl<'de> DecodeBorrow<'de> for AlterShareGroupOffsetsRequestTopic<'de> {
147    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
148        let flex = version >= 0;
149        let mut out = Self::default();
150        if version >= 0 { out.topic_name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
151        if version >= 0 { out.partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(AlterShareGroupOffsetsRequestPartition::decode_borrow(buf, version)?); } v }; }
152        if flex {
153            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
154                Ok(false)
155            })?;
156        }
157        Ok(out)
158    }
159}
160
161#[derive(Debug, Clone, PartialEq, Eq)]
162pub struct AlterShareGroupOffsetsRequestPartition {
163    pub partition_index: i32,
164    pub start_offset: i64,
165    pub unknown_tagged_fields: UnknownTaggedFields,
166}
167
168impl Default for AlterShareGroupOffsetsRequestPartition {
169    fn default() -> Self {
170        Self {
171            partition_index: 0i32,
172            start_offset: 0i64,
173            unknown_tagged_fields: Default::default(),
174        }
175    }
176}
177
178impl AlterShareGroupOffsetsRequestPartition {
179    pub fn to_owned(&self) -> crate::owned::alter_share_group_offsets_request::AlterShareGroupOffsetsRequestPartition {
180        crate::owned::alter_share_group_offsets_request::AlterShareGroupOffsetsRequestPartition {
181            partition_index: (self.partition_index),
182            start_offset: (self.start_offset),
183            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
184        }
185    }
186}
187
188impl Encode for AlterShareGroupOffsetsRequestPartition {
189    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
190        let flex = version >= 0;
191        if version >= 0 { put_i32(buf, self.partition_index) }
192        if version >= 0 { put_i64(buf, self.start_offset) }
193        if flex {
194            let tagged = WriteTaggedFields::new();
195            tagged.write(buf, &self.unknown_tagged_fields);
196        }
197        Ok(())
198    }
199    fn encoded_len(&self, version: i16) -> usize {
200        let flex = version >= 0;
201        let mut n: usize = 0;
202        if version >= 0 { n += 4; }
203        if version >= 0 { n += 8; }
204        if flex {
205            let known_pairs: Vec<(u32, usize)> = Vec::new();
206            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
207        }
208        n
209    }
210}
211
212impl<'de> DecodeBorrow<'de> for AlterShareGroupOffsetsRequestPartition {
213    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
214        let flex = version >= 0;
215        let mut out = Self::default();
216        if version >= 0 { out.partition_index = get_i32(buf)?; }
217        if version >= 0 { out.start_offset = get_i64(buf)?; }
218        if flex {
219            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
220                Ok(false)
221            })?;
222        }
223        Ok(out)
224    }
225}