Skip to main content

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