Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
OffsetCommitResponse.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, put_i16, put_i32};
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};
12
13pub const API_KEY: i16 = 8;
14pub const MIN_VERSION: i16 = 2;
15pub const MAX_VERSION: i16 = 10;
16pub const FLEXIBLE_MIN: i16 = 8;
17
18#[inline]
19fn is_flexible(version: i16) -> bool {
20    version >= FLEXIBLE_MIN
21}
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct OffsetCommitResponse {
25    pub throttle_time_ms: i32,
26    pub topics: Vec<OffsetCommitResponseTopic>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29impl Encode for OffsetCommitResponse {
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 {
33                api_key: API_KEY,
34                version,
35            });
36        }
37        let flex = is_flexible(version);
38        if version >= 3 {
39            put_i32(buf, self.throttle_time_ms);
40        }
41        if version >= 0 {
42            {
43                crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
44                for it in &self.topics {
45                    it.encode(buf, version)?;
46                }
47            }
48        }
49        if flex {
50            let tagged = WriteTaggedFields::new();
51            tagged.write(buf, &self.unknown_tagged_fields);
52        }
53        Ok(())
54    }
55    fn encoded_len(&self, version: i16) -> usize {
56        let flex = is_flexible(version);
57        let mut n: usize = 0;
58        if version >= 3 {
59            n += 4;
60        }
61        if version >= 0 {
62            n += {
63                let prefix =
64                    crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
65                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
66                prefix + body
67            };
68        }
69        if flex {
70            let known_pairs: Vec<(u32, usize)> = Vec::new();
71            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
72        }
73        n
74    }
75}
76impl Decode<'_> for OffsetCommitResponse {
77    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
78        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
79            return Err(ProtocolError::UnsupportedVersion {
80                api_key: API_KEY,
81                version,
82            });
83        }
84        let flex = is_flexible(version);
85        let mut out = Self::default();
86        if version >= 3 {
87            out.throttle_time_ms = get_i32(buf)?;
88        }
89        if version >= 0 {
90            out.topics = {
91                let n = crate::primitives::array::get_array_len(buf, flex)?;
92                let mut v = Vec::with_capacity(n);
93                for _ in 0..n {
94                    v.push(OffsetCommitResponseTopic::decode(buf, version)?);
95                }
96                v
97            };
98        }
99        if flex {
100            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
101        }
102        Ok(out)
103    }
104}
105#[cfg(test)]
106impl OffsetCommitResponse {
107    #[must_use]
108    pub fn populated(version: i16) -> Self {
109        let mut m = Self::default();
110        if version >= 3 {
111            m.throttle_time_ms = 1i32;
112        }
113        if version >= 0 {
114            m.topics = vec![OffsetCommitResponseTopic::populated(version)];
115        }
116        m
117    }
118}
119#[derive(Debug, Clone, PartialEq, Eq, Default)]
120pub struct OffsetCommitResponseTopic {
121    pub name: String,
122    pub topic_id: crate::primitives::uuid::Uuid,
123    pub partitions: Vec<OffsetCommitResponsePartition>,
124    pub unknown_tagged_fields: UnknownTaggedFields,
125}
126impl Encode for OffsetCommitResponseTopic {
127    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
128        let flex = version >= 8;
129        if (0..=9).contains(&version) {
130            if flex {
131                put_compact_string(buf, &self.name);
132            } else {
133                put_string(buf, &self.name);
134            }
135        }
136        if version >= 10 {
137            crate::primitives::uuid::put_uuid(buf, self.topic_id);
138        }
139        if version >= 0 {
140            {
141                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
142                for it in &self.partitions {
143                    it.encode(buf, version)?;
144                }
145            }
146        }
147        if flex {
148            let tagged = WriteTaggedFields::new();
149            tagged.write(buf, &self.unknown_tagged_fields);
150        }
151        Ok(())
152    }
153    fn encoded_len(&self, version: i16) -> usize {
154        let flex = version >= 8;
155        let mut n: usize = 0;
156        if (0..=9).contains(&version) {
157            n += if flex {
158                compact_string_len(&self.name)
159            } else {
160                string_len(&self.name)
161            };
162        }
163        if version >= 10 {
164            n += 16;
165        }
166        if version >= 0 {
167            n += {
168                let prefix =
169                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
170                let body: usize = (self.partitions)
171                    .iter()
172                    .map(|it| it.encoded_len(version))
173                    .sum();
174                prefix + body
175            };
176        }
177        if flex {
178            let known_pairs: Vec<(u32, usize)> = Vec::new();
179            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
180        }
181        n
182    }
183}
184impl Decode<'_> for OffsetCommitResponseTopic {
185    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
186        let flex = version >= 8;
187        let mut out = Self::default();
188        if (0..=9).contains(&version) {
189            out.name = if flex {
190                get_compact_string_owned(buf)?
191            } else {
192                get_string_owned(buf)?
193            };
194        }
195        if version >= 10 {
196            out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
197        }
198        if version >= 0 {
199            out.partitions = {
200                let n = crate::primitives::array::get_array_len(buf, flex)?;
201                let mut v = Vec::with_capacity(n);
202                for _ in 0..n {
203                    v.push(OffsetCommitResponsePartition::decode(buf, version)?);
204                }
205                v
206            };
207        }
208        if flex {
209            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
210        }
211        Ok(out)
212    }
213}
214#[cfg(test)]
215impl OffsetCommitResponseTopic {
216    #[must_use]
217    pub fn populated(version: i16) -> Self {
218        let mut m = Self::default();
219        if (0..=9).contains(&version) {
220            m.name = "x".to_string();
221        }
222        if version >= 10 {
223            m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
224        }
225        if version >= 0 {
226            m.partitions = vec![OffsetCommitResponsePartition::populated(version)];
227        }
228        m
229    }
230}
231#[derive(Debug, Clone, PartialEq, Eq, Default)]
232pub struct OffsetCommitResponsePartition {
233    pub partition_index: i32,
234    pub error_code: i16,
235    pub unknown_tagged_fields: UnknownTaggedFields,
236}
237impl Encode for OffsetCommitResponsePartition {
238    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
239        let flex = version >= 8;
240        if version >= 0 {
241            put_i32(buf, self.partition_index);
242        }
243        if version >= 0 {
244            put_i16(buf, self.error_code);
245        }
246        if flex {
247            let tagged = WriteTaggedFields::new();
248            tagged.write(buf, &self.unknown_tagged_fields);
249        }
250        Ok(())
251    }
252    fn encoded_len(&self, version: i16) -> usize {
253        let flex = version >= 8;
254        let mut n: usize = 0;
255        if version >= 0 {
256            n += 4;
257        }
258        if version >= 0 {
259            n += 2;
260        }
261        if flex {
262            let known_pairs: Vec<(u32, usize)> = Vec::new();
263            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
264        }
265        n
266    }
267}
268impl Decode<'_> for OffsetCommitResponsePartition {
269    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
270        let flex = version >= 8;
271        let mut out = Self::default();
272        if version >= 0 {
273            out.partition_index = get_i32(buf)?;
274        }
275        if version >= 0 {
276            out.error_code = get_i16(buf)?;
277        }
278        if flex {
279            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
280        }
281        Ok(out)
282    }
283}
284#[cfg(test)]
285impl OffsetCommitResponsePartition {
286    #[must_use]
287    pub fn populated(version: i16) -> Self {
288        let mut m = Self::default();
289        if version >= 0 {
290            m.partition_index = 1i32;
291        }
292        if version >= 0 {
293            m.error_code = 1i16;
294        }
295        m
296    }
297}
298
299/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
300/// Only includes fields valid for the given version.
301#[must_use]
302#[allow(unused_comparisons)]
303pub fn default_json(version: i16) -> ::serde_json::Value {
304    let mut obj = ::serde_json::Map::new();
305    if version >= 3 {
306        obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
307    }
308    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
309    ::serde_json::Value::Object(obj)
310}