Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
EndQuorumEpochRequest.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_u16, put_i32, put_u16};
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::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
16use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
17
18pub const API_KEY: i16 = 54;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 1;
21pub const FLEXIBLE_MIN: i16 = 1;
22
23#[inline]
24fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
25
26#[derive(Debug, Clone, PartialEq, Eq)]
27pub struct EndQuorumEpochRequest<'a> {
28    pub cluster_id: Option<&'a str>,
29    pub topics: Vec<TopicData<'a>>,
30    pub leader_endpoints: Vec<LeaderEndpoint<'a>>,
31    pub unknown_tagged_fields: UnknownTaggedFields,
32}
33
34impl<'a> Default for EndQuorumEpochRequest<'a> {
35    fn default() -> Self {
36        Self {
37            cluster_id: None,
38            topics: Vec::new(),
39            leader_endpoints: Vec::new(),
40            unknown_tagged_fields: Default::default(),
41        }
42    }
43}
44
45impl<'a> EndQuorumEpochRequest<'a> {
46    pub fn to_owned(&self) -> crate::owned::end_quorum_epoch_request::EndQuorumEpochRequest {
47        crate::owned::end_quorum_epoch_request::EndQuorumEpochRequest {
48            cluster_id: (self.cluster_id).map(|s| s.to_string()),
49            topics: (self.topics).iter().map(|it| it.to_owned()).collect(),
50            leader_endpoints: (self.leader_endpoints).iter().map(|it| it.to_owned()).collect(),
51            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
52        }
53    }
54}
55
56impl<'a> Encode for EndQuorumEpochRequest<'a> {
57    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
58        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
59            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
60        }
61        let flex = is_flexible(version);
62        if version >= 0 { if flex { put_compact_nullable_string(buf, self.cluster_id) } else { put_nullable_string(buf, self.cluster_id) } }
63        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
64        if version >= 1 { { crate::primitives::array::put_array_len(buf, (self.leader_endpoints).len(), flex); for it in &self.leader_endpoints { it.encode(buf, version)?; } } }
65        if flex {
66            let tagged = WriteTaggedFields::new();
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 += if flex { compact_nullable_string_len(self.cluster_id) } else { nullable_string_len(self.cluster_id) }; }
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 version >= 1 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.leader_endpoints).len(), flex); let body: usize = (self.leader_endpoints).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
77        if flex {
78            let known_pairs: Vec<(u32, usize)> = Vec::new();
79            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
80        }
81        n
82    }
83}
84
85impl<'de> DecodeBorrow<'de> for EndQuorumEpochRequest<'de> {
86    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
87        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
88            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
89        }
90        let flex = is_flexible(version);
91        let mut out = Self::default();
92        if version >= 0 { out.cluster_id = if flex { get_compact_nullable_string_borrowed(buf)? } else { get_nullable_string_borrowed(buf)? }; }
93        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 }; }
94        if version >= 1 { out.leader_endpoints = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(LeaderEndpoint::decode_borrow(buf, version)?); } v }; }
95        if flex {
96            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
97                Ok(false)
98            })?;
99        }
100        Ok(out)
101    }
102}
103
104#[derive(Debug, Clone, PartialEq, Eq)]
105pub struct TopicData<'a> {
106    pub topic_name: &'a str,
107    pub partitions: Vec<PartitionData>,
108    pub unknown_tagged_fields: UnknownTaggedFields,
109}
110
111impl<'a> Default for TopicData<'a> {
112    fn default() -> Self {
113        Self {
114            topic_name: "",
115            partitions: Vec::new(),
116            unknown_tagged_fields: Default::default(),
117        }
118    }
119}
120
121impl<'a> TopicData<'a> {
122    pub fn to_owned(&self) -> crate::owned::end_quorum_epoch_request::TopicData {
123        crate::owned::end_quorum_epoch_request::TopicData {
124            topic_name: (self.topic_name).to_string(),
125            partitions: (self.partitions).iter().map(|it| it.to_owned()).collect(),
126            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
127        }
128    }
129}
130
131impl<'a> Encode for TopicData<'a> {
132    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
133        let flex = version >= 1;
134        if version >= 0 { if flex { put_compact_string(buf, self.topic_name) } else { put_string(buf, self.topic_name) } }
135        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
136        if flex {
137            let tagged = WriteTaggedFields::new();
138            tagged.write(buf, &self.unknown_tagged_fields);
139        }
140        Ok(())
141    }
142    fn encoded_len(&self, version: i16) -> usize {
143        let flex = version >= 1;
144        let mut n: usize = 0;
145        if version >= 0 { n += if flex { compact_string_len(self.topic_name) } else { string_len(self.topic_name) }; }
146        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 }; }
147        if flex {
148            let known_pairs: Vec<(u32, usize)> = Vec::new();
149            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
150        }
151        n
152    }
153}
154
155impl<'de> DecodeBorrow<'de> for TopicData<'de> {
156    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
157        let flex = version >= 1;
158        let mut out = Self::default();
159        if version >= 0 { out.topic_name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
160        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 }; }
161        if flex {
162            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
163                Ok(false)
164            })?;
165        }
166        Ok(out)
167    }
168}
169
170#[derive(Debug, Clone, PartialEq, Eq)]
171pub struct PartitionData {
172    pub partition_index: i32,
173    pub leader_id: i32,
174    pub leader_epoch: i32,
175    pub preferred_successors: Vec<i32>,
176    pub preferred_candidates: Vec<ReplicaInfo>,
177    pub unknown_tagged_fields: UnknownTaggedFields,
178}
179
180impl Default for PartitionData {
181    fn default() -> Self {
182        Self {
183            partition_index: 0i32,
184            leader_id: 0i32,
185            leader_epoch: 0i32,
186            preferred_successors: Vec::new(),
187            preferred_candidates: Vec::new(),
188            unknown_tagged_fields: Default::default(),
189        }
190    }
191}
192
193impl PartitionData {
194    pub fn to_owned(&self) -> crate::owned::end_quorum_epoch_request::PartitionData {
195        crate::owned::end_quorum_epoch_request::PartitionData {
196            partition_index: (self.partition_index),
197            leader_id: (self.leader_id),
198            leader_epoch: (self.leader_epoch),
199            preferred_successors: (self.preferred_successors).clone(),
200            preferred_candidates: (self.preferred_candidates).iter().map(|it| it.to_owned()).collect(),
201            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
202        }
203    }
204}
205
206impl Encode for PartitionData {
207    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
208        let flex = version >= 1;
209        if version >= 0 { put_i32(buf, self.partition_index) }
210        if version >= 0 { put_i32(buf, self.leader_id) }
211        if version >= 0 { put_i32(buf, self.leader_epoch) }
212        if version >= 0 && version <= 0 { { crate::primitives::array::put_array_len(buf, (self.preferred_successors).len(), flex); for it in &self.preferred_successors { put_i32(buf, *it); } } }
213        if version >= 1 { { crate::primitives::array::put_array_len(buf, (self.preferred_candidates).len(), flex); for it in &self.preferred_candidates { it.encode(buf, version)?; } } }
214        if flex {
215            let tagged = WriteTaggedFields::new();
216            tagged.write(buf, &self.unknown_tagged_fields);
217        }
218        Ok(())
219    }
220    fn encoded_len(&self, version: i16) -> usize {
221        let flex = version >= 1;
222        let mut n: usize = 0;
223        if version >= 0 { n += 4; }
224        if version >= 0 { n += 4; }
225        if version >= 0 { n += 4; }
226        if version >= 0 && version <= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.preferred_successors).len(), flex); let body: usize = (self.preferred_successors).iter().map(|_| 4).sum(); prefix + body }; }
227        if version >= 1 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.preferred_candidates).len(), flex); let body: usize = (self.preferred_candidates).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
228        if flex {
229            let known_pairs: Vec<(u32, usize)> = Vec::new();
230            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
231        }
232        n
233    }
234}
235
236impl<'de> DecodeBorrow<'de> for PartitionData {
237    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
238        let flex = version >= 1;
239        let mut out = Self::default();
240        if version >= 0 { out.partition_index = get_i32(buf)?; }
241        if version >= 0 { out.leader_id = get_i32(buf)?; }
242        if version >= 0 { out.leader_epoch = get_i32(buf)?; }
243        if version >= 0 && version <= 0 { out.preferred_successors = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } v }; }
244        if version >= 1 { out.preferred_candidates = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(ReplicaInfo::decode_borrow(buf, version)?); } v }; }
245        if flex {
246            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
247                Ok(false)
248            })?;
249        }
250        Ok(out)
251    }
252}
253
254#[derive(Debug, Clone, PartialEq, Eq)]
255pub struct ReplicaInfo {
256    pub candidate_id: i32,
257    pub candidate_directory_id: crate::primitives::uuid::Uuid,
258    pub unknown_tagged_fields: UnknownTaggedFields,
259}
260
261impl Default for ReplicaInfo {
262    fn default() -> Self {
263        Self {
264            candidate_id: 0i32,
265            candidate_directory_id: Default::default(),
266            unknown_tagged_fields: Default::default(),
267        }
268    }
269}
270
271impl ReplicaInfo {
272    pub fn to_owned(&self) -> crate::owned::end_quorum_epoch_request::ReplicaInfo {
273        crate::owned::end_quorum_epoch_request::ReplicaInfo {
274            candidate_id: (self.candidate_id),
275            candidate_directory_id: (self.candidate_directory_id),
276            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
277        }
278    }
279}
280
281impl Encode for ReplicaInfo {
282    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
283        let flex = version >= 1;
284        if version >= 1 { put_i32(buf, self.candidate_id) }
285        if version >= 1 { crate::primitives::uuid::put_uuid(buf, self.candidate_directory_id) }
286        if flex {
287            let tagged = WriteTaggedFields::new();
288            tagged.write(buf, &self.unknown_tagged_fields);
289        }
290        Ok(())
291    }
292    fn encoded_len(&self, version: i16) -> usize {
293        let flex = version >= 1;
294        let mut n: usize = 0;
295        if version >= 1 { n += 4; }
296        if version >= 1 { n += 16; }
297        if flex {
298            let known_pairs: Vec<(u32, usize)> = Vec::new();
299            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
300        }
301        n
302    }
303}
304
305impl<'de> DecodeBorrow<'de> for ReplicaInfo {
306    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
307        let flex = version >= 1;
308        let mut out = Self::default();
309        if version >= 1 { out.candidate_id = get_i32(buf)?; }
310        if version >= 1 { out.candidate_directory_id = crate::primitives::uuid::get_uuid(buf)?; }
311        if flex {
312            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
313                Ok(false)
314            })?;
315        }
316        Ok(out)
317    }
318}
319
320#[derive(Debug, Clone, PartialEq, Eq)]
321pub struct LeaderEndpoint<'a> {
322    pub name: &'a str,
323    pub host: &'a str,
324    pub port: u16,
325    pub unknown_tagged_fields: UnknownTaggedFields,
326}
327
328impl<'a> Default for LeaderEndpoint<'a> {
329    fn default() -> Self {
330        Self {
331            name: "",
332            host: "",
333            port: 0u16,
334            unknown_tagged_fields: Default::default(),
335        }
336    }
337}
338
339impl<'a> LeaderEndpoint<'a> {
340    pub fn to_owned(&self) -> crate::owned::end_quorum_epoch_request::LeaderEndpoint {
341        crate::owned::end_quorum_epoch_request::LeaderEndpoint {
342            name: (self.name).to_string(),
343            host: (self.host).to_string(),
344            port: (self.port),
345            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
346        }
347    }
348}
349
350impl<'a> Encode for LeaderEndpoint<'a> {
351    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
352        let flex = version >= 1;
353        if version >= 1 { if flex { put_compact_string(buf, self.name) } else { put_string(buf, self.name) } }
354        if version >= 1 { if flex { put_compact_string(buf, self.host) } else { put_string(buf, self.host) } }
355        if version >= 1 { put_u16(buf, self.port) }
356        if flex {
357            let tagged = WriteTaggedFields::new();
358            tagged.write(buf, &self.unknown_tagged_fields);
359        }
360        Ok(())
361    }
362    fn encoded_len(&self, version: i16) -> usize {
363        let flex = version >= 1;
364        let mut n: usize = 0;
365        if version >= 1 { n += if flex { compact_string_len(self.name) } else { string_len(self.name) }; }
366        if version >= 1 { n += if flex { compact_string_len(self.host) } else { string_len(self.host) }; }
367        if version >= 1 { n += 2; }
368        if flex {
369            let known_pairs: Vec<(u32, usize)> = Vec::new();
370            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
371        }
372        n
373    }
374}
375
376impl<'de> DecodeBorrow<'de> for LeaderEndpoint<'de> {
377    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
378        let flex = version >= 1;
379        let mut out = Self::default();
380        if version >= 1 { out.name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
381        if version >= 1 { out.host = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
382        if version >= 1 { out.port = get_u16(buf)?; }
383        if flex {
384            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
385                Ok(false)
386            })?;
387        }
388        Ok(out)
389    }
390}