Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ReadShareGroupStateRequest.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_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 = 84;
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 ReadShareGroupStateRequest<'a> {
25    pub group_id: &'a str,
26    pub topics: Vec<ReadStateData>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29
30impl<'a> Default for ReadShareGroupStateRequest<'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> ReadShareGroupStateRequest<'a> {
41    pub fn to_owned(&self) -> crate::owned::read_share_group_state_request::ReadShareGroupStateRequest {
42        crate::owned::read_share_group_state_request::ReadShareGroupStateRequest {
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 ReadShareGroupStateRequest<'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 ReadShareGroupStateRequest<'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(ReadStateData::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 ReadStateData {
97    pub topic_id: crate::primitives::uuid::Uuid,
98    pub partitions: Vec<PartitionData>,
99    pub unknown_tagged_fields: UnknownTaggedFields,
100}
101
102impl Default for ReadStateData {
103    fn default() -> Self {
104        Self {
105            topic_id: Default::default(),
106            partitions: Vec::new(),
107            unknown_tagged_fields: Default::default(),
108        }
109    }
110}
111
112impl ReadStateData {
113    pub fn to_owned(&self) -> crate::owned::read_share_group_state_request::ReadStateData {
114        crate::owned::read_share_group_state_request::ReadStateData {
115            topic_id: (self.topic_id),
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 Encode for ReadStateData {
123    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
124        let flex = version >= 0;
125        if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
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 += 16; }
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 ReadStateData {
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_id = crate::primitives::uuid::get_uuid(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(PartitionData::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 PartitionData {
163    pub partition: i32,
164    pub leader_epoch: i32,
165    pub unknown_tagged_fields: UnknownTaggedFields,
166}
167
168impl Default for PartitionData {
169    fn default() -> Self {
170        Self {
171            partition: 0i32,
172            leader_epoch: 0i32,
173            unknown_tagged_fields: Default::default(),
174        }
175    }
176}
177
178impl PartitionData {
179    pub fn to_owned(&self) -> crate::owned::read_share_group_state_request::PartitionData {
180        crate::owned::read_share_group_state_request::PartitionData {
181            partition: (self.partition),
182            leader_epoch: (self.leader_epoch),
183            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
184        }
185    }
186}
187
188impl Encode for PartitionData {
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) }
192        if version >= 0 { put_i32(buf, self.leader_epoch) }
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 += 4; }
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 PartitionData {
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 = get_i32(buf)?; }
217        if version >= 0 { out.leader_epoch = get_i32(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}