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,
8    put_compact_string, put_string, string_len,
9};
10use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
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 { version >= FLEXIBLE_MIN }
20
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct OffsetCommitResponse {
23    pub throttle_time_ms: i32,
24    pub topics: Vec<OffsetCommitResponseTopic>,
25    pub unknown_tagged_fields: UnknownTaggedFields,
26}
27
28impl Encode for OffsetCommitResponse {
29    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
30        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
31            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
32        }
33        let flex = is_flexible(version);
34        if version >= 3 { put_i32(buf, self.throttle_time_ms) }
35        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { 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 >= 3 { n += 4; }
46        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 }; }
47        if flex {
48            let known_pairs: Vec<(u32, usize)> = Vec::new();
49            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
50        }
51        n
52    }
53}
54
55impl<'de> Decode<'de> for OffsetCommitResponse {
56    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
57        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
58            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
59        }
60        let flex = is_flexible(version);
61        let mut out = Self::default();
62        if version >= 3 { out.throttle_time_ms = get_i32(buf)?; }
63        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(OffsetCommitResponseTopic::decode(buf, version)?); } v }; }
64        if flex {
65            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
66                Ok(false)
67            })?;
68        }
69        Ok(out)
70    }
71}
72
73#[derive(Debug, Clone, PartialEq, Eq, Default)]
74pub struct OffsetCommitResponseTopic {
75    pub name: String,
76    pub topic_id: crate::primitives::uuid::Uuid,
77    pub partitions: Vec<OffsetCommitResponsePartition>,
78    pub unknown_tagged_fields: UnknownTaggedFields,
79}
80
81impl Encode for OffsetCommitResponseTopic {
82    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
83        let flex = version >= 8;
84        if version >= 0 && version <= 9 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
85        if version >= 10 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
86        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
87        if flex {
88            let tagged = WriteTaggedFields::new();
89            tagged.write(buf, &self.unknown_tagged_fields);
90        }
91        Ok(())
92    }
93    fn encoded_len(&self, version: i16) -> usize {
94        let flex = version >= 8;
95        let mut n: usize = 0;
96        if version >= 0 && version <= 9 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
97        if version >= 10 { n += 16; }
98        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 }; }
99        if flex {
100            let known_pairs: Vec<(u32, usize)> = Vec::new();
101            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
102        }
103        n
104    }
105}
106
107impl<'de> Decode<'de> for OffsetCommitResponseTopic {
108    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
109        let flex = version >= 8;
110        let mut out = Self::default();
111        if version >= 0 && version <= 9 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
112        if version >= 10 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
113        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(OffsetCommitResponsePartition::decode(buf, version)?); } v }; }
114        if flex {
115            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
116                Ok(false)
117            })?;
118        }
119        Ok(out)
120    }
121}
122
123#[derive(Debug, Clone, PartialEq, Eq, Default)]
124pub struct OffsetCommitResponsePartition {
125    pub partition_index: i32,
126    pub error_code: i16,
127    pub unknown_tagged_fields: UnknownTaggedFields,
128}
129
130impl Encode for OffsetCommitResponsePartition {
131    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
132        let flex = version >= 8;
133        if version >= 0 { put_i32(buf, self.partition_index) }
134        if version >= 0 { put_i16(buf, self.error_code) }
135        if flex {
136            let tagged = WriteTaggedFields::new();
137            tagged.write(buf, &self.unknown_tagged_fields);
138        }
139        Ok(())
140    }
141    fn encoded_len(&self, version: i16) -> usize {
142        let flex = version >= 8;
143        let mut n: usize = 0;
144        if version >= 0 { n += 4; }
145        if version >= 0 { n += 2; }
146        if flex {
147            let known_pairs: Vec<(u32, usize)> = Vec::new();
148            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
149        }
150        n
151    }
152}
153
154impl<'de> Decode<'de> for OffsetCommitResponsePartition {
155    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
156        let flex = version >= 8;
157        let mut out = Self::default();
158        if version >= 0 { out.partition_index = get_i32(buf)?; }
159        if version >= 0 { out.error_code = get_i16(buf)?; }
160        if flex {
161            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
162                Ok(false)
163            })?;
164        }
165        Ok(out)
166    }
167}
168
169/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
170/// Only includes fields valid for the given version.
171#[must_use]
172#[allow(unused_comparisons)]
173pub fn default_json(version: i16) -> ::serde_json::Value {
174    let mut obj = ::serde_json::Map::new();
175    if version >= 3 {
176        obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
177    }
178    obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
179    ::serde_json::Value::Object(obj)
180}