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::{get_bool, get_i32, get_i64, get_i8, put_bool, put_i32, put_i64, put_i8};
6use crate::primitives::string_bytes::{
7    compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8    get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
10    string_len,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
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 { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct ShareAcknowledgeRequest {
25    pub group_id: Option<String>,
26    pub member_id: Option<String>,
27    pub share_session_epoch: i32,
28    pub is_renew_ack: bool,
29    pub topics: Vec<AcknowledgeTopic>,
30    pub unknown_tagged_fields: UnknownTaggedFields,
31}
32
33impl Encode for ShareAcknowledgeRequest {
34    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
35        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
36            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
37        }
38        let flex = is_flexible(version);
39        if version >= 0 { if flex { put_compact_nullable_string(buf, self.group_id.as_deref()) } else { put_nullable_string(buf, self.group_id.as_deref()) } }
40        if version >= 0 { if flex { put_compact_nullable_string(buf, self.member_id.as_deref()) } else { put_nullable_string(buf, self.member_id.as_deref()) } }
41        if version >= 0 { put_i32(buf, self.share_session_epoch) }
42        if version >= 2 { put_bool(buf, self.is_renew_ack) }
43        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
44        if flex {
45            let tagged = WriteTaggedFields::new();
46            tagged.write(buf, &self.unknown_tagged_fields);
47        }
48        Ok(())
49    }
50    fn encoded_len(&self, version: i16) -> usize {
51        let flex = is_flexible(version);
52        let mut n: usize = 0;
53        if version >= 0 { n += if flex { compact_nullable_string_len(self.group_id.as_deref()) } else { nullable_string_len(self.group_id.as_deref()) }; }
54        if version >= 0 { n += if flex { compact_nullable_string_len(self.member_id.as_deref()) } else { nullable_string_len(self.member_id.as_deref()) }; }
55        if version >= 0 { n += 4; }
56        if version >= 2 { n += 1; }
57        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topics).len(), flex); let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
58        if flex {
59            let known_pairs: Vec<(u32, usize)> = Vec::new();
60            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
61        }
62        n
63    }
64}
65
66impl<'de> Decode<'de> for ShareAcknowledgeRequest {
67    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
68        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
69            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
70        }
71        let flex = is_flexible(version);
72        let mut out = Self::default();
73        if version >= 0 { out.group_id = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
74        if version >= 0 { out.member_id = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
75        if version >= 0 { out.share_session_epoch = get_i32(buf)?; }
76        if version >= 2 { out.is_renew_ack = get_bool(buf)?; }
77        if version >= 0 { out.topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(AcknowledgeTopic::decode(buf, version)?); } v }; }
78        if flex {
79            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
80                Ok(false)
81            })?;
82        }
83        Ok(out)
84    }
85}
86
87#[derive(Debug, Clone, PartialEq, Eq, Default)]
88pub struct AcknowledgeTopic {
89    pub topic_id: crate::primitives::uuid::Uuid,
90    pub partitions: Vec<AcknowledgePartition>,
91    pub unknown_tagged_fields: UnknownTaggedFields,
92}
93
94impl Encode for AcknowledgeTopic {
95    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
96        let flex = version >= 0;
97        if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
98        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
99        if flex {
100            let tagged = WriteTaggedFields::new();
101            tagged.write(buf, &self.unknown_tagged_fields);
102        }
103        Ok(())
104    }
105    fn encoded_len(&self, version: i16) -> usize {
106        let flex = version >= 0;
107        let mut n: usize = 0;
108        if version >= 0 { n += 16; }
109        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 }; }
110        if flex {
111            let known_pairs: Vec<(u32, usize)> = Vec::new();
112            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
113        }
114        n
115    }
116}
117
118impl<'de> Decode<'de> for AcknowledgeTopic {
119    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
120        let flex = version >= 0;
121        let mut out = Self::default();
122        if version >= 0 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
123        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(AcknowledgePartition::decode(buf, version)?); } v }; }
124        if flex {
125            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
126                Ok(false)
127            })?;
128        }
129        Ok(out)
130    }
131}
132
133#[derive(Debug, Clone, PartialEq, Eq, Default)]
134pub struct AcknowledgePartition {
135    pub partition_index: i32,
136    pub acknowledgement_batches: Vec<AcknowledgementBatch>,
137    pub unknown_tagged_fields: UnknownTaggedFields,
138}
139
140impl Encode for AcknowledgePartition {
141    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
142        let flex = version >= 0;
143        if version >= 0 { put_i32(buf, self.partition_index) }
144        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.acknowledgement_batches).len(), flex); for it in &self.acknowledgement_batches { it.encode(buf, version)?; } } }
145        if flex {
146            let tagged = WriteTaggedFields::new();
147            tagged.write(buf, &self.unknown_tagged_fields);
148        }
149        Ok(())
150    }
151    fn encoded_len(&self, version: i16) -> usize {
152        let flex = version >= 0;
153        let mut n: usize = 0;
154        if version >= 0 { n += 4; }
155        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.acknowledgement_batches).len(), flex); let body: usize = (self.acknowledgement_batches).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
156        if flex {
157            let known_pairs: Vec<(u32, usize)> = Vec::new();
158            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
159        }
160        n
161    }
162}
163
164impl<'de> Decode<'de> for AcknowledgePartition {
165    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
166        let flex = version >= 0;
167        let mut out = Self::default();
168        if version >= 0 { out.partition_index = get_i32(buf)?; }
169        if version >= 0 { out.acknowledgement_batches = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(AcknowledgementBatch::decode(buf, version)?); } v }; }
170        if flex {
171            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
172                Ok(false)
173            })?;
174        }
175        Ok(out)
176    }
177}
178
179#[derive(Debug, Clone, PartialEq, Eq, Default)]
180pub struct AcknowledgementBatch {
181    pub first_offset: i64,
182    pub last_offset: i64,
183    pub acknowledge_types: Vec<i8>,
184    pub unknown_tagged_fields: UnknownTaggedFields,
185}
186
187impl Encode for AcknowledgementBatch {
188    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
189        let flex = version >= 0;
190        if version >= 0 { put_i64(buf, self.first_offset) }
191        if version >= 0 { put_i64(buf, self.last_offset) }
192        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.acknowledge_types).len(), flex); for it in &self.acknowledge_types { put_i8(buf, *it); } } }
193        if flex {
194            let tagged = WriteTaggedFields::new();
195            tagged.write(buf, &self.unknown_tagged_fields);
196        }
197        Ok(())
198    }
199    fn encoded_len(&self, version: i16) -> usize {
200        let flex = version >= 0;
201        let mut n: usize = 0;
202        if version >= 0 { n += 8; }
203        if version >= 0 { n += 8; }
204        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.acknowledge_types).len(), flex); let body: usize = (self.acknowledge_types).iter().map(|_| 1).sum(); prefix + body }; }
205        if flex {
206            let known_pairs: Vec<(u32, usize)> = Vec::new();
207            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
208        }
209        n
210    }
211}
212
213impl<'de> Decode<'de> for AcknowledgementBatch {
214    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
215        let flex = version >= 0;
216        let mut out = Self::default();
217        if version >= 0 { out.first_offset = get_i64(buf)?; }
218        if version >= 0 { out.last_offset = get_i64(buf)?; }
219        if version >= 0 { out.acknowledge_types = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i8(buf)?); } v }; }
220        if flex {
221            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
222                Ok(false)
223            })?;
224        }
225        Ok(out)
226    }
227}
228
229/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
230/// Only includes fields valid for the given version.
231#[must_use]
232#[allow(unused_comparisons)]
233pub fn default_json(version: i16) -> ::serde_json::Value {
234    let mut obj = ::serde_json::Map::new();
235    obj.insert("groupId".to_string(), ::serde_json::Value::Null);
236    obj.insert("memberId".to_string(), ::serde_json::Value::Null);
237    obj.insert("shareSessionEpoch".to_string(), ::serde_json::json!(0));
238    if version >= 2 {
239        obj.insert("isRenewAck".to_string(), ::serde_json::Value::Bool(false));
240    }
241    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
242    ::serde_json::Value::Object(obj)
243}
244
245impl crate::ProtocolRequest for ShareAcknowledgeRequest {
246    const API_KEY: i16 = API_KEY;
247    const MIN_VERSION: i16 = MIN_VERSION;
248    const MAX_VERSION: i16 = MAX_VERSION;
249    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
250    type Response = super::share_acknowledge_response::ShareAcknowledgeResponse;
251}