Skip to main content

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