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