Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
OffsetCommitResponse.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
6use crate::primitives::string_bytes::{
7    compact_string_len, put_compact_string, put_string, string_len,
8};
9use crate::primitives::string_bytes_borrowed::{
10    get_compact_string_borrowed, get_string_borrowed,
11};
12use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
13use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
14
15pub const API_KEY: i16 = 8;
16pub const MIN_VERSION: i16 = 2;
17pub const MAX_VERSION: i16 = 10;
18pub const FLEXIBLE_MIN: i16 = 8;
19
20#[inline]
21fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
22
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct OffsetCommitResponse<'a> {
25    pub throttle_time_ms: i32,
26    pub topics: Vec<OffsetCommitResponseTopic<'a>>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29
30impl<'a> Default for OffsetCommitResponse<'a> {
31    fn default() -> Self {
32        Self {
33            throttle_time_ms: 0i32,
34            topics: Vec::new(),
35            unknown_tagged_fields: Default::default(),
36        }
37    }
38}
39
40impl<'a> OffsetCommitResponse<'a> {
41    pub fn to_owned(&self) -> crate::owned::offset_commit_response::OffsetCommitResponse {
42        crate::owned::offset_commit_response::OffsetCommitResponse {
43            throttle_time_ms: (self.throttle_time_ms),
44            topics: (self.topics).iter().map(|it| it.to_owned()).collect(),
45            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
46        }
47    }
48}
49
50impl<'a> Encode for OffsetCommitResponse<'a> {
51    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
52        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
53            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
54        }
55        let flex = is_flexible(version);
56        if version >= 3 { put_i32(buf, self.throttle_time_ms) }
57        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
58        if flex {
59            let tagged = WriteTaggedFields::new();
60            tagged.write(buf, &self.unknown_tagged_fields);
61        }
62        Ok(())
63    }
64    fn encoded_len(&self, version: i16) -> usize {
65        let flex = is_flexible(version);
66        let mut n: usize = 0;
67        if version >= 3 { n += 4; }
68        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 }; }
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}
76
77impl<'de> DecodeBorrow<'de> for OffsetCommitResponse<'de> {
78    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
79        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
80            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
81        }
82        let flex = is_flexible(version);
83        let mut out = Self::default();
84        if version >= 3 { out.throttle_time_ms = get_i32(buf)?; }
85        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_borrow(buf, version)?); } v }; }
86        if flex {
87            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
88                Ok(false)
89            })?;
90        }
91        Ok(out)
92    }
93}
94
95#[derive(Debug, Clone, PartialEq, Eq)]
96pub struct OffsetCommitResponseTopic<'a> {
97    pub name: &'a str,
98    pub topic_id: crate::primitives::uuid::Uuid,
99    pub partitions: Vec<OffsetCommitResponsePartition>,
100    pub unknown_tagged_fields: UnknownTaggedFields,
101}
102
103impl<'a> Default for OffsetCommitResponseTopic<'a> {
104    fn default() -> Self {
105        Self {
106            name: "",
107            topic_id: Default::default(),
108            partitions: Vec::new(),
109            unknown_tagged_fields: Default::default(),
110        }
111    }
112}
113
114impl<'a> OffsetCommitResponseTopic<'a> {
115    pub fn to_owned(&self) -> crate::owned::offset_commit_response::OffsetCommitResponseTopic {
116        crate::owned::offset_commit_response::OffsetCommitResponseTopic {
117            name: (self.name).to_string(),
118            topic_id: (self.topic_id),
119            partitions: (self.partitions).iter().map(|it| it.to_owned()).collect(),
120            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
121        }
122    }
123}
124
125impl<'a> Encode for OffsetCommitResponseTopic<'a> {
126    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
127        let flex = version >= 8;
128        if version >= 0 && version <= 9 { if flex { put_compact_string(buf, self.name) } else { put_string(buf, self.name) } }
129        if version >= 10 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
130        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
131        if flex {
132            let tagged = WriteTaggedFields::new();
133            tagged.write(buf, &self.unknown_tagged_fields);
134        }
135        Ok(())
136    }
137    fn encoded_len(&self, version: i16) -> usize {
138        let flex = version >= 8;
139        let mut n: usize = 0;
140        if version >= 0 && version <= 9 { n += if flex { compact_string_len(self.name) } else { string_len(self.name) }; }
141        if version >= 10 { n += 16; }
142        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 }; }
143        if flex {
144            let known_pairs: Vec<(u32, usize)> = Vec::new();
145            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
146        }
147        n
148    }
149}
150
151impl<'de> DecodeBorrow<'de> for OffsetCommitResponseTopic<'de> {
152    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
153        let flex = version >= 8;
154        let mut out = Self::default();
155        if version >= 0 && version <= 9 { out.name = if flex { get_compact_string_borrowed(buf)? } else { get_string_borrowed(buf)? }; }
156        if version >= 10 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
157        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_borrow(buf, version)?); } v }; }
158        if flex {
159            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
160                Ok(false)
161            })?;
162        }
163        Ok(out)
164    }
165}
166
167#[derive(Debug, Clone, PartialEq, Eq)]
168pub struct OffsetCommitResponsePartition {
169    pub partition_index: i32,
170    pub error_code: i16,
171    pub unknown_tagged_fields: UnknownTaggedFields,
172}
173
174impl Default for OffsetCommitResponsePartition {
175    fn default() -> Self {
176        Self {
177            partition_index: 0i32,
178            error_code: 0i16,
179            unknown_tagged_fields: Default::default(),
180        }
181    }
182}
183
184impl OffsetCommitResponsePartition {
185    pub fn to_owned(&self) -> crate::owned::offset_commit_response::OffsetCommitResponsePartition {
186        crate::owned::offset_commit_response::OffsetCommitResponsePartition {
187            partition_index: (self.partition_index),
188            error_code: (self.error_code),
189            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
190        }
191    }
192}
193
194impl Encode for OffsetCommitResponsePartition {
195    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
196        let flex = version >= 8;
197        if version >= 0 { put_i32(buf, self.partition_index) }
198        if version >= 0 { put_i16(buf, self.error_code) }
199        if flex {
200            let tagged = WriteTaggedFields::new();
201            tagged.write(buf, &self.unknown_tagged_fields);
202        }
203        Ok(())
204    }
205    fn encoded_len(&self, version: i16) -> usize {
206        let flex = version >= 8;
207        let mut n: usize = 0;
208        if version >= 0 { n += 4; }
209        if version >= 0 { n += 2; }
210        if flex {
211            let known_pairs: Vec<(u32, usize)> = Vec::new();
212            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
213        }
214        n
215    }
216}
217
218impl<'de> DecodeBorrow<'de> for OffsetCommitResponsePartition {
219    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
220        let flex = version >= 8;
221        let mut out = Self::default();
222        if version >= 0 { out.partition_index = get_i32(buf)?; }
223        if version >= 0 { out.error_code = 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}