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