Skip to main content

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

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