Skip to main content

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