Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i16, get_i32, get_u16, put_i16, put_i32, put_u16};
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::{encode_to_bytes, read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{Decode, DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 53;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 1;
18pub const FLEXIBLE_MIN: i16 = 1;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct BeginQuorumEpochResponse<'a> {
25    pub error_code: i16,
26    pub topics: Vec<TopicData<'a>>,
27    pub node_endpoints: Vec<crate::owned::begin_quorum_epoch_response::NodeEndpoint>,
28    pub unknown_tagged_fields: UnknownTaggedFields,
29}
30
31impl<'a> Default for BeginQuorumEpochResponse<'a> {
32    fn default() -> Self {
33        Self {
34            error_code: 0i16,
35            topics: Vec::new(),
36            node_endpoints: Vec::new(),
37            unknown_tagged_fields: Default::default(),
38        }
39    }
40}
41
42impl<'a> BeginQuorumEpochResponse<'a> {
43    pub fn to_owned(&self) -> crate::owned::begin_quorum_epoch_response::BeginQuorumEpochResponse {
44        crate::owned::begin_quorum_epoch_response::BeginQuorumEpochResponse {
45            error_code: (self.error_code),
46            topics: (self.topics).iter().map(|it| it.to_owned()).collect(),
47            node_endpoints: self.node_endpoints.clone(),
48            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
49        }
50    }
51}
52
53impl<'a> Encode for BeginQuorumEpochResponse<'a> {
54    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
55        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
56            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
57        }
58        let flex = is_flexible(version);
59        if version >= 0 { put_i16(buf, self.error_code) }
60        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
61        if flex {
62            let mut tagged = WriteTaggedFields::new();
63            if !(crate::codegen_helpers::is_default(&self.node_endpoints)) {
64                let payload = encode_to_bytes({ let prefix = crate::primitives::array::array_len_prefix_len((self.node_endpoints).len(), flex); let body: usize = (self.node_endpoints).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }, |b| { { crate::primitives::array::put_array_len(b, (self.node_endpoints).len(), flex); for it in &self.node_endpoints { it.encode(b, version)?; } }; Ok(()) });
65                tagged.add(0, payload);
66            }
67            tagged.write(buf, &self.unknown_tagged_fields);
68        }
69        Ok(())
70    }
71    fn encoded_len(&self, version: i16) -> usize {
72        let flex = is_flexible(version);
73        let mut n: usize = 0;
74        if version >= 0 { n += 2; }
75        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 }; }
76        if flex {
77            let mut known_pairs: Vec<(u32, usize)> = Vec::new();
78            if !(crate::codegen_helpers::is_default(&self.node_endpoints)) {
79                known_pairs.push((0, { let prefix = crate::primitives::array::array_len_prefix_len((self.node_endpoints).len(), flex); let body: usize = (self.node_endpoints).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }));
80            }
81            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
82        }
83        n
84    }
85}
86
87impl<'de> DecodeBorrow<'de> for BeginQuorumEpochResponse<'de> {
88    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
89        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
90            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
91        }
92        let flex = is_flexible(version);
93        let mut out = Self::default();
94        if version >= 0 { out.error_code = get_i16(buf)?; }
95        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(TopicData::decode_borrow(buf, version)?); } v }; }
96        if flex {
97            // Pre-declare typed slots for known tagged fields.
98            let mut tag_node_endpoints = None;
99            out.unknown_tagged_fields = read_tagged_fields(buf, |tag, payload| {
100                match tag {
101                0 => { tag_node_endpoints = Some({ let b: &mut &[u8] = payload; { let n = crate::primitives::array::get_array_len(b, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(crate::owned::begin_quorum_epoch_response::NodeEndpoint::decode(b, version)?); } v } }); Ok(true) }
102                    _ => Ok(false),
103                }
104            })?;
105            if let Some(v) = tag_node_endpoints { out.node_endpoints = v; }
106        }
107        Ok(out)
108    }
109}
110
111#[derive(Debug, Clone, PartialEq, Eq)]
112pub struct TopicData<'a> {
113    pub topic_name: &'a str,
114    pub partitions: Vec<PartitionData>,
115    pub unknown_tagged_fields: UnknownTaggedFields,
116}
117
118impl<'a> Default for TopicData<'a> {
119    fn default() -> Self {
120        Self {
121            topic_name: "",
122            partitions: Vec::new(),
123            unknown_tagged_fields: Default::default(),
124        }
125    }
126}
127
128impl<'a> TopicData<'a> {
129    pub fn to_owned(&self) -> crate::owned::begin_quorum_epoch_response::TopicData {
130        crate::owned::begin_quorum_epoch_response::TopicData {
131            topic_name: (self.topic_name).to_string(),
132            partitions: (self.partitions).iter().map(|it| it.to_owned()).collect(),
133            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
134        }
135    }
136}
137
138impl<'a> Encode for TopicData<'a> {
139    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
140        let flex = version >= 1;
141        if version >= 0 { if flex { put_compact_string(buf, self.topic_name) } else { put_string(buf, self.topic_name) } }
142        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
143        if flex {
144            let tagged = WriteTaggedFields::new();
145            tagged.write(buf, &self.unknown_tagged_fields);
146        }
147        Ok(())
148    }
149    fn encoded_len(&self, version: i16) -> usize {
150        let flex = version >= 1;
151        let mut n: usize = 0;
152        if version >= 0 { n += if flex { compact_string_len(self.topic_name) } else { string_len(self.topic_name) }; }
153        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 }; }
154        if flex {
155            let known_pairs: Vec<(u32, usize)> = Vec::new();
156            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
157        }
158        n
159    }
160}
161
162impl<'de> DecodeBorrow<'de> for TopicData<'de> {
163    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
164        let flex = version >= 1;
165        let mut out = Self::default();
166        if version >= 0 { out.topic_name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
167        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 }; }
168        if flex {
169            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
170                Ok(false)
171            })?;
172        }
173        Ok(out)
174    }
175}
176
177#[derive(Debug, Clone, PartialEq, Eq)]
178pub struct PartitionData {
179    pub partition_index: i32,
180    pub error_code: i16,
181    pub leader_id: i32,
182    pub leader_epoch: i32,
183    pub unknown_tagged_fields: UnknownTaggedFields,
184}
185
186impl Default for PartitionData {
187    fn default() -> Self {
188        Self {
189            partition_index: 0i32,
190            error_code: 0i16,
191            leader_id: 0i32,
192            leader_epoch: 0i32,
193            unknown_tagged_fields: Default::default(),
194        }
195    }
196}
197
198impl PartitionData {
199    pub fn to_owned(&self) -> crate::owned::begin_quorum_epoch_response::PartitionData {
200        crate::owned::begin_quorum_epoch_response::PartitionData {
201            partition_index: (self.partition_index),
202            error_code: (self.error_code),
203            leader_id: (self.leader_id),
204            leader_epoch: (self.leader_epoch),
205            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
206        }
207    }
208}
209
210impl Encode for PartitionData {
211    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
212        let flex = version >= 1;
213        if version >= 0 { put_i32(buf, self.partition_index) }
214        if version >= 0 { put_i16(buf, self.error_code) }
215        if version >= 0 { put_i32(buf, self.leader_id) }
216        if version >= 0 { put_i32(buf, self.leader_epoch) }
217        if flex {
218            let tagged = WriteTaggedFields::new();
219            tagged.write(buf, &self.unknown_tagged_fields);
220        }
221        Ok(())
222    }
223    fn encoded_len(&self, version: i16) -> usize {
224        let flex = version >= 1;
225        let mut n: usize = 0;
226        if version >= 0 { n += 4; }
227        if version >= 0 { n += 2; }
228        if version >= 0 { n += 4; }
229        if version >= 0 { n += 4; }
230        if flex {
231            let known_pairs: Vec<(u32, usize)> = Vec::new();
232            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
233        }
234        n
235    }
236}
237
238impl<'de> DecodeBorrow<'de> for PartitionData {
239    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
240        let flex = version >= 1;
241        let mut out = Self::default();
242        if version >= 0 { out.partition_index = get_i32(buf)?; }
243        if version >= 0 { out.error_code = get_i16(buf)?; }
244        if version >= 0 { out.leader_id = get_i32(buf)?; }
245        if version >= 0 { out.leader_epoch = get_i32(buf)?; }
246        if flex {
247            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
248                Ok(false)
249            })?;
250        }
251        Ok(out)
252    }
253}
254
255#[derive(Debug, Clone, PartialEq, Eq)]
256pub struct NodeEndpoint<'a> {
257    pub node_id: i32,
258    pub host: &'a str,
259    pub port: u16,
260    pub unknown_tagged_fields: UnknownTaggedFields,
261}
262
263impl<'a> Default for NodeEndpoint<'a> {
264    fn default() -> Self {
265        Self {
266            node_id: 0i32,
267            host: "",
268            port: 0u16,
269            unknown_tagged_fields: Default::default(),
270        }
271    }
272}
273
274impl<'a> NodeEndpoint<'a> {
275    pub fn to_owned(&self) -> crate::owned::begin_quorum_epoch_response::NodeEndpoint {
276        crate::owned::begin_quorum_epoch_response::NodeEndpoint {
277            node_id: (self.node_id),
278            host: (self.host).to_string(),
279            port: (self.port),
280            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
281        }
282    }
283}
284
285impl<'a> Encode for NodeEndpoint<'a> {
286    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
287        let flex = version >= 1;
288        if version >= 1 { put_i32(buf, self.node_id) }
289        if version >= 1 { if flex { put_compact_string(buf, self.host) } else { put_string(buf, self.host) } }
290        if version >= 1 { put_u16(buf, self.port) }
291        if flex {
292            let tagged = WriteTaggedFields::new();
293            tagged.write(buf, &self.unknown_tagged_fields);
294        }
295        Ok(())
296    }
297    fn encoded_len(&self, version: i16) -> usize {
298        let flex = version >= 1;
299        let mut n: usize = 0;
300        if version >= 1 { n += 4; }
301        if version >= 1 { n += if flex { compact_string_len(self.host) } else { string_len(self.host) }; }
302        if version >= 1 { n += 2; }
303        if flex {
304            let known_pairs: Vec<(u32, usize)> = Vec::new();
305            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
306        }
307        n
308    }
309}
310
311impl<'de> DecodeBorrow<'de> for NodeEndpoint<'de> {
312    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
313        let flex = version >= 1;
314        let mut out = Self::default();
315        if version >= 1 { out.node_id = get_i32(buf)?; }
316        if version >= 1 { out.host = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
317        if version >= 1 { out.port = get_u16(buf)?; }
318        if flex {
319            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
320                Ok(false)
321            })?;
322        }
323        Ok(out)
324    }
325}