Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::BufMut;
4
5use crate::primitives::fixed::{
6    get_bool, get_i8, get_i32, get_i64, put_bool, put_i8, put_i32, put_i64,
7};
8use crate::primitives::string_bytes::{
9    compact_nullable_string_len, nullable_string_len, put_compact_nullable_string,
10    put_nullable_string,
11};
12use crate::primitives::string_bytes_borrowed::{
13    get_compact_nullable_string_borrowed, get_nullable_string_borrowed,
14};
15use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
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 {
25    version >= FLEXIBLE_MIN
26}
27
28#[derive(Debug, Clone, PartialEq, Eq, Default)]
29pub struct ShareAcknowledgeRequest<'a> {
30    pub group_id: Option<&'a str>,
31    pub member_id: Option<&'a str>,
32    pub share_session_epoch: i32,
33    pub is_renew_ack: bool,
34    pub topics: Vec<AcknowledgeTopic>,
35    pub unknown_tagged_fields: UnknownTaggedFields,
36}
37impl ShareAcknowledgeRequest<'_> {
38    pub fn to_owned(&self) -> crate::owned::share_acknowledge_request::ShareAcknowledgeRequest {
39        crate::owned::share_acknowledge_request::ShareAcknowledgeRequest {
40            group_id: (self.group_id).map(std::string::ToString::to_string),
41            member_id: (self.member_id).map(std::string::ToString::to_string),
42            share_session_epoch: (self.share_session_epoch),
43            is_renew_ack: (self.is_renew_ack),
44            topics: (self.topics)
45                .iter()
46                .map(AcknowledgeTopic::to_owned)
47                .collect(),
48            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
49        }
50    }
51}
52impl Encode for ShareAcknowledgeRequest<'_> {
53    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
54        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
55            return Err(ProtocolError::UnsupportedVersion {
56                api_key: API_KEY,
57                version,
58            });
59        }
60        let flex = is_flexible(version);
61        if version >= 0 {
62            if flex {
63                put_compact_nullable_string(buf, self.group_id);
64            } else {
65                put_nullable_string(buf, self.group_id);
66            }
67        }
68        if version >= 0 {
69            if flex {
70                put_compact_nullable_string(buf, self.member_id);
71            } else {
72                put_nullable_string(buf, self.member_id);
73            }
74        }
75        if version >= 0 {
76            put_i32(buf, self.share_session_epoch);
77        }
78        if version >= 2 {
79            put_bool(buf, self.is_renew_ack);
80        }
81        if version >= 0 {
82            {
83                crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
84                for it in &self.topics {
85                    it.encode(buf, version)?;
86                }
87            }
88        }
89        if flex {
90            let tagged = WriteTaggedFields::new();
91            tagged.write(buf, &self.unknown_tagged_fields);
92        }
93        Ok(())
94    }
95    fn encoded_len(&self, version: i16) -> usize {
96        let flex = is_flexible(version);
97        let mut n: usize = 0;
98        if version >= 0 {
99            n += if flex {
100                compact_nullable_string_len(self.group_id)
101            } else {
102                nullable_string_len(self.group_id)
103            };
104        }
105        if version >= 0 {
106            n += if flex {
107                compact_nullable_string_len(self.member_id)
108            } else {
109                nullable_string_len(self.member_id)
110            };
111        }
112        if version >= 0 {
113            n += 4;
114        }
115        if version >= 2 {
116            n += 1;
117        }
118        if version >= 0 {
119            n += {
120                let prefix =
121                    crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
122                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
123                prefix + body
124            };
125        }
126        if flex {
127            let known_pairs: Vec<(u32, usize)> = Vec::new();
128            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
129        }
130        n
131    }
132}
133impl<'de> DecodeBorrow<'de> for ShareAcknowledgeRequest<'de> {
134    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
135        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
136            return Err(ProtocolError::UnsupportedVersion {
137                api_key: API_KEY,
138                version,
139            });
140        }
141        let flex = is_flexible(version);
142        let mut out = Self::default();
143        if version >= 0 {
144            out.group_id = if flex {
145                get_compact_nullable_string_borrowed(buf)?
146            } else {
147                get_nullable_string_borrowed(buf)?
148            };
149        }
150        if version >= 0 {
151            out.member_id = if flex {
152                get_compact_nullable_string_borrowed(buf)?
153            } else {
154                get_nullable_string_borrowed(buf)?
155            };
156        }
157        if version >= 0 {
158            out.share_session_epoch = get_i32(buf)?;
159        }
160        if version >= 2 {
161            out.is_renew_ack = get_bool(buf)?;
162        }
163        if version >= 0 {
164            out.topics = {
165                let n = crate::primitives::array::get_array_len(buf, flex)?;
166                let mut v = Vec::with_capacity(n);
167                for _ in 0..n {
168                    v.push(AcknowledgeTopic::decode_borrow(buf, version)?);
169                }
170                v
171            };
172        }
173        if flex {
174            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
175        }
176        Ok(out)
177    }
178}
179#[cfg(test)]
180impl ShareAcknowledgeRequest<'_> {
181    #[must_use]
182    pub fn populated(version: i16) -> Self {
183        let mut m = Self::default();
184        if version >= 0 {
185            m.group_id = Some("x");
186        }
187        if version >= 0 {
188            m.member_id = Some("x");
189        }
190        if version >= 0 {
191            m.share_session_epoch = 1i32;
192        }
193        if version >= 2 {
194            m.is_renew_ack = true;
195        }
196        if version >= 0 {
197            m.topics = vec![AcknowledgeTopic::populated(version)];
198        }
199        m
200    }
201}
202#[derive(Debug, Clone, PartialEq, Eq, Default)]
203pub struct AcknowledgeTopic {
204    pub topic_id: crate::primitives::uuid::Uuid,
205    pub partitions: Vec<AcknowledgePartition>,
206    pub unknown_tagged_fields: UnknownTaggedFields,
207}
208impl AcknowledgeTopic {
209    pub fn to_owned(&self) -> crate::owned::share_acknowledge_request::AcknowledgeTopic {
210        crate::owned::share_acknowledge_request::AcknowledgeTopic {
211            topic_id: (self.topic_id),
212            partitions: (self.partitions)
213                .iter()
214                .map(AcknowledgePartition::to_owned)
215                .collect(),
216            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
217        }
218    }
219}
220impl Encode for AcknowledgeTopic {
221    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
222        let flex = version >= 0;
223        if version >= 0 {
224            crate::primitives::uuid::put_uuid(buf, self.topic_id);
225        }
226        if version >= 0 {
227            {
228                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
229                for it in &self.partitions {
230                    it.encode(buf, version)?;
231                }
232            }
233        }
234        if flex {
235            let tagged = WriteTaggedFields::new();
236            tagged.write(buf, &self.unknown_tagged_fields);
237        }
238        Ok(())
239    }
240    fn encoded_len(&self, version: i16) -> usize {
241        let flex = version >= 0;
242        let mut n: usize = 0;
243        if version >= 0 {
244            n += 16;
245        }
246        if version >= 0 {
247            n += {
248                let prefix =
249                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
250                let body: usize = (self.partitions)
251                    .iter()
252                    .map(|it| it.encoded_len(version))
253                    .sum();
254                prefix + body
255            };
256        }
257        if flex {
258            let known_pairs: Vec<(u32, usize)> = Vec::new();
259            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
260        }
261        n
262    }
263}
264impl<'de> DecodeBorrow<'de> for AcknowledgeTopic {
265    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
266        let flex = version >= 0;
267        let mut out = Self::default();
268        if version >= 0 {
269            out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
270        }
271        if version >= 0 {
272            out.partitions = {
273                let n = crate::primitives::array::get_array_len(buf, flex)?;
274                let mut v = Vec::with_capacity(n);
275                for _ in 0..n {
276                    v.push(AcknowledgePartition::decode_borrow(buf, version)?);
277                }
278                v
279            };
280        }
281        if flex {
282            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
283        }
284        Ok(out)
285    }
286}
287#[cfg(test)]
288impl AcknowledgeTopic {
289    #[must_use]
290    pub fn populated(version: i16) -> Self {
291        let mut m = Self::default();
292        if version >= 0 {
293            m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
294        }
295        if version >= 0 {
296            m.partitions = vec![AcknowledgePartition::populated(version)];
297        }
298        m
299    }
300}
301#[derive(Debug, Clone, PartialEq, Eq, Default)]
302pub struct AcknowledgePartition {
303    pub partition_index: i32,
304    pub acknowledgement_batches: Vec<AcknowledgementBatch>,
305    pub unknown_tagged_fields: UnknownTaggedFields,
306}
307impl AcknowledgePartition {
308    pub fn to_owned(&self) -> crate::owned::share_acknowledge_request::AcknowledgePartition {
309        crate::owned::share_acknowledge_request::AcknowledgePartition {
310            partition_index: (self.partition_index),
311            acknowledgement_batches: (self.acknowledgement_batches)
312                .iter()
313                .map(AcknowledgementBatch::to_owned)
314                .collect(),
315            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
316        }
317    }
318}
319impl Encode for AcknowledgePartition {
320    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
321        let flex = version >= 0;
322        if version >= 0 {
323            put_i32(buf, self.partition_index);
324        }
325        if version >= 0 {
326            {
327                crate::primitives::array::put_array_len(
328                    buf,
329                    (self.acknowledgement_batches).len(),
330                    flex,
331                );
332                for it in &self.acknowledgement_batches {
333                    it.encode(buf, version)?;
334                }
335            }
336        }
337        if flex {
338            let tagged = WriteTaggedFields::new();
339            tagged.write(buf, &self.unknown_tagged_fields);
340        }
341        Ok(())
342    }
343    fn encoded_len(&self, version: i16) -> usize {
344        let flex = version >= 0;
345        let mut n: usize = 0;
346        if version >= 0 {
347            n += 4;
348        }
349        if version >= 0 {
350            n += {
351                let prefix = crate::primitives::array::array_len_prefix_len(
352                    (self.acknowledgement_batches).len(),
353                    flex,
354                );
355                let body: usize = (self.acknowledgement_batches)
356                    .iter()
357                    .map(|it| it.encoded_len(version))
358                    .sum();
359                prefix + body
360            };
361        }
362        if flex {
363            let known_pairs: Vec<(u32, usize)> = Vec::new();
364            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
365        }
366        n
367    }
368}
369impl<'de> DecodeBorrow<'de> for AcknowledgePartition {
370    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
371        let flex = version >= 0;
372        let mut out = Self::default();
373        if version >= 0 {
374            out.partition_index = get_i32(buf)?;
375        }
376        if version >= 0 {
377            out.acknowledgement_batches = {
378                let n = crate::primitives::array::get_array_len(buf, flex)?;
379                let mut v = Vec::with_capacity(n);
380                for _ in 0..n {
381                    v.push(AcknowledgementBatch::decode_borrow(buf, version)?);
382                }
383                v
384            };
385        }
386        if flex {
387            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
388        }
389        Ok(out)
390    }
391}
392#[cfg(test)]
393impl AcknowledgePartition {
394    #[must_use]
395    pub fn populated(version: i16) -> Self {
396        let mut m = Self::default();
397        if version >= 0 {
398            m.partition_index = 1i32;
399        }
400        if version >= 0 {
401            m.acknowledgement_batches = vec![AcknowledgementBatch::populated(version)];
402        }
403        m
404    }
405}
406#[derive(Debug, Clone, PartialEq, Eq, Default)]
407pub struct AcknowledgementBatch {
408    pub first_offset: i64,
409    pub last_offset: i64,
410    pub acknowledge_types: Vec<i8>,
411    pub unknown_tagged_fields: UnknownTaggedFields,
412}
413impl AcknowledgementBatch {
414    pub fn to_owned(&self) -> crate::owned::share_acknowledge_request::AcknowledgementBatch {
415        crate::owned::share_acknowledge_request::AcknowledgementBatch {
416            first_offset: (self.first_offset),
417            last_offset: (self.last_offset),
418            acknowledge_types: (self.acknowledge_types).clone(),
419            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
420        }
421    }
422}
423impl Encode for AcknowledgementBatch {
424    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
425        let flex = version >= 0;
426        if version >= 0 {
427            put_i64(buf, self.first_offset);
428        }
429        if version >= 0 {
430            put_i64(buf, self.last_offset);
431        }
432        if version >= 0 {
433            {
434                crate::primitives::array::put_array_len(buf, (self.acknowledge_types).len(), flex);
435                for it in &self.acknowledge_types {
436                    put_i8(buf, *it);
437                }
438            }
439        }
440        if flex {
441            let tagged = WriteTaggedFields::new();
442            tagged.write(buf, &self.unknown_tagged_fields);
443        }
444        Ok(())
445    }
446    fn encoded_len(&self, version: i16) -> usize {
447        let flex = version >= 0;
448        let mut n: usize = 0;
449        if version >= 0 {
450            n += 8;
451        }
452        if version >= 0 {
453            n += 8;
454        }
455        if version >= 0 {
456            n += {
457                let prefix = crate::primitives::array::array_len_prefix_len(
458                    (self.acknowledge_types).len(),
459                    flex,
460                );
461                let body: usize = (self.acknowledge_types).iter().map(|_| 1).sum();
462                prefix + body
463            };
464        }
465        if flex {
466            let known_pairs: Vec<(u32, usize)> = Vec::new();
467            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
468        }
469        n
470    }
471}
472impl<'de> DecodeBorrow<'de> for AcknowledgementBatch {
473    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
474        let flex = version >= 0;
475        let mut out = Self::default();
476        if version >= 0 {
477            out.first_offset = get_i64(buf)?;
478        }
479        if version >= 0 {
480            out.last_offset = get_i64(buf)?;
481        }
482        if version >= 0 {
483            out.acknowledge_types = {
484                let n = crate::primitives::array::get_array_len(buf, flex)?;
485                let mut v = Vec::with_capacity(n);
486                for _ in 0..n {
487                    v.push(get_i8(buf)?);
488                }
489                v
490            };
491        }
492        if flex {
493            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
494        }
495        Ok(out)
496    }
497}
498#[cfg(test)]
499impl AcknowledgementBatch {
500    #[must_use]
501    pub fn populated(version: i16) -> Self {
502        let mut m = Self::default();
503        if version >= 0 {
504            m.first_offset = 1i64;
505        }
506        if version >= 0 {
507            m.last_offset = 1i64;
508        }
509        if version >= 0 {
510            m.acknowledge_types = vec![1i8];
511        }
512        m
513    }
514}