Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AlterPartitionResponse.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, get_i8, put_i16, put_i32, put_i8};
6use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
7use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
8
9pub const API_KEY: i16 = 56;
10pub const MIN_VERSION: i16 = 2;
11pub const MAX_VERSION: i16 = 3;
12pub const FLEXIBLE_MIN: i16 = 0;
13
14#[inline]
15fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
16
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct AlterPartitionResponse {
19    pub throttle_time_ms: i32,
20    pub error_code: i16,
21    pub topics: Vec<TopicData>,
22    pub unknown_tagged_fields: UnknownTaggedFields,
23}
24
25impl Default for AlterPartitionResponse {
26    fn default() -> Self {
27        Self {
28            throttle_time_ms: 0i32,
29            error_code: 0i16,
30            topics: Vec::new(),
31            unknown_tagged_fields: Default::default(),
32        }
33    }
34}
35
36impl AlterPartitionResponse {
37    pub fn to_owned(&self) -> crate::owned::alter_partition_response::AlterPartitionResponse {
38        crate::owned::alter_partition_response::AlterPartitionResponse {
39            throttle_time_ms: (self.throttle_time_ms),
40            error_code: (self.error_code),
41            topics: (self.topics).iter().map(|it| it.to_owned()).collect(),
42            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
43        }
44    }
45}
46
47impl Encode for AlterPartitionResponse {
48    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
49        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
50            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
51        }
52        let flex = is_flexible(version);
53        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
54        if version >= 0 { put_i16(buf, self.error_code) }
55        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
56        if flex {
57            let tagged = WriteTaggedFields::new();
58            tagged.write(buf, &self.unknown_tagged_fields);
59        }
60        Ok(())
61    }
62    fn encoded_len(&self, version: i16) -> usize {
63        let flex = is_flexible(version);
64        let mut n: usize = 0;
65        if version >= 0 { n += 4; }
66        if version >= 0 { n += 2; }
67        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 }; }
68        if flex {
69            let known_pairs: Vec<(u32, usize)> = Vec::new();
70            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
71        }
72        n
73    }
74}
75
76impl<'de> DecodeBorrow<'de> for AlterPartitionResponse {
77    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
78        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
79            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
80        }
81        let flex = is_flexible(version);
82        let mut out = Self::default();
83        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
84        if version >= 0 { out.error_code = get_i16(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(TopicData::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 TopicData {
97    pub topic_id: crate::primitives::uuid::Uuid,
98    pub partitions: Vec<PartitionData>,
99    pub unknown_tagged_fields: UnknownTaggedFields,
100}
101
102impl Default for TopicData {
103    fn default() -> Self {
104        Self {
105            topic_id: Default::default(),
106            partitions: Vec::new(),
107            unknown_tagged_fields: Default::default(),
108        }
109    }
110}
111
112impl TopicData {
113    pub fn to_owned(&self) -> crate::owned::alter_partition_response::TopicData {
114        crate::owned::alter_partition_response::TopicData {
115            topic_id: (self.topic_id),
116            partitions: (self.partitions).iter().map(|it| it.to_owned()).collect(),
117            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
118        }
119    }
120}
121
122impl Encode for TopicData {
123    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
124        let flex = version >= 0;
125        if version >= 2 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
126        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
127        if flex {
128            let tagged = WriteTaggedFields::new();
129            tagged.write(buf, &self.unknown_tagged_fields);
130        }
131        Ok(())
132    }
133    fn encoded_len(&self, version: i16) -> usize {
134        let flex = version >= 0;
135        let mut n: usize = 0;
136        if version >= 2 { n += 16; }
137        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 }; }
138        if flex {
139            let known_pairs: Vec<(u32, usize)> = Vec::new();
140            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
141        }
142        n
143    }
144}
145
146impl<'de> DecodeBorrow<'de> for TopicData {
147    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
148        let flex = version >= 0;
149        let mut out = Self::default();
150        if version >= 2 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
151        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(PartitionData::decode_borrow(buf, version)?); } v }; }
152        if flex {
153            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
154                Ok(false)
155            })?;
156        }
157        Ok(out)
158    }
159}
160
161#[derive(Debug, Clone, PartialEq, Eq)]
162pub struct PartitionData {
163    pub partition_index: i32,
164    pub error_code: i16,
165    pub leader_id: i32,
166    pub leader_epoch: i32,
167    pub isr: Vec<i32>,
168    pub leader_recovery_state: i8,
169    pub partition_epoch: i32,
170    pub unknown_tagged_fields: UnknownTaggedFields,
171}
172
173impl Default for PartitionData {
174    fn default() -> Self {
175        Self {
176            partition_index: 0i32,
177            error_code: 0i16,
178            leader_id: 0i32,
179            leader_epoch: 0i32,
180            isr: Vec::new(),
181            leader_recovery_state: 0i8,
182            partition_epoch: 0i32,
183            unknown_tagged_fields: Default::default(),
184        }
185    }
186}
187
188impl PartitionData {
189    pub fn to_owned(&self) -> crate::owned::alter_partition_response::PartitionData {
190        crate::owned::alter_partition_response::PartitionData {
191            partition_index: (self.partition_index),
192            error_code: (self.error_code),
193            leader_id: (self.leader_id),
194            leader_epoch: (self.leader_epoch),
195            isr: (self.isr).clone(),
196            leader_recovery_state: (self.leader_recovery_state),
197            partition_epoch: (self.partition_epoch),
198            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
199        }
200    }
201}
202
203impl Encode for PartitionData {
204    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
205        let flex = version >= 0;
206        if version >= 0 { put_i32(buf, self.partition_index) }
207        if version >= 0 { put_i16(buf, self.error_code) }
208        if version >= 0 { put_i32(buf, self.leader_id) }
209        if version >= 0 { put_i32(buf, self.leader_epoch) }
210        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.isr).len(), flex); for it in &self.isr { put_i32(buf, *it); } } }
211        if version >= 1 { put_i8(buf, self.leader_recovery_state) }
212        if version >= 0 { put_i32(buf, self.partition_epoch) }
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 += 2; }
224        if version >= 0 { n += 4; }
225        if version >= 0 { n += 4; }
226        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.isr).len(), flex); let body: usize = (self.isr).iter().map(|_| 4).sum(); prefix + body }; }
227        if version >= 1 { n += 1; }
228        if version >= 0 { n += 4; }
229        if flex {
230            let known_pairs: Vec<(u32, usize)> = Vec::new();
231            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
232        }
233        n
234    }
235}
236
237impl<'de> DecodeBorrow<'de> for PartitionData {
238    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
239        let flex = version >= 0;
240        let mut out = Self::default();
241        if version >= 0 { out.partition_index = get_i32(buf)?; }
242        if version >= 0 { out.error_code = get_i16(buf)?; }
243        if version >= 0 { out.leader_id = get_i32(buf)?; }
244        if version >= 0 { out.leader_epoch = get_i32(buf)?; }
245        if version >= 0 { out.isr = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } v }; }
246        if version >= 1 { out.leader_recovery_state = get_i8(buf)?; }
247        if version >= 0 { out.partition_epoch = get_i32(buf)?; }
248        if flex {
249            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
250                Ok(false)
251            })?;
252        }
253        Ok(out)
254    }
255}