Skip to main content

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

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