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