Skip to main content

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

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