Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AssignReplicasToDirsResponse.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::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
7use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
8
9pub const API_KEY: i16 = 73;
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 0;
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 AssignReplicasToDirsResponse {
19    pub throttle_time_ms: i32,
20    pub error_code: i16,
21    pub directories: Vec<DirectoryData>,
22    pub unknown_tagged_fields: UnknownTaggedFields,
23}
24
25impl Default for AssignReplicasToDirsResponse {
26    fn default() -> Self {
27        Self {
28            throttle_time_ms: 0i32,
29            error_code: 0i16,
30            directories: Vec::new(),
31            unknown_tagged_fields: Default::default(),
32        }
33    }
34}
35
36impl AssignReplicasToDirsResponse {
37    pub fn to_owned(&self) -> crate::owned::assign_replicas_to_dirs_response::AssignReplicasToDirsResponse {
38        crate::owned::assign_replicas_to_dirs_response::AssignReplicasToDirsResponse {
39            throttle_time_ms: (self.throttle_time_ms),
40            error_code: (self.error_code),
41            directories: (self.directories).iter().map(|it| it.to_owned()).collect(),
42            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
43        }
44    }
45}
46
47impl Encode for AssignReplicasToDirsResponse {
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.directories).len(), flex); for it in &self.directories { 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.directories).len(), flex); let body: usize = (self.directories).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 AssignReplicasToDirsResponse {
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.directories = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DirectoryData::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 DirectoryData {
97    pub id: crate::primitives::uuid::Uuid,
98    pub topics: Vec<TopicData>,
99    pub unknown_tagged_fields: UnknownTaggedFields,
100}
101
102impl Default for DirectoryData {
103    fn default() -> Self {
104        Self {
105            id: Default::default(),
106            topics: Vec::new(),
107            unknown_tagged_fields: Default::default(),
108        }
109    }
110}
111
112impl DirectoryData {
113    pub fn to_owned(&self) -> crate::owned::assign_replicas_to_dirs_response::DirectoryData {
114        crate::owned::assign_replicas_to_dirs_response::DirectoryData {
115            id: (self.id),
116            topics: (self.topics).iter().map(|it| it.to_owned()).collect(),
117            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
118        }
119    }
120}
121
122impl Encode for DirectoryData {
123    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
124        let flex = version >= 0;
125        if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.id) }
126        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { 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 >= 0 { n += 16; }
137        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 }; }
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 DirectoryData {
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 >= 0 { out.id = crate::primitives::uuid::get_uuid(buf)?; }
151        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 }; }
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 TopicData {
163    pub topic_id: crate::primitives::uuid::Uuid,
164    pub partitions: Vec<PartitionData>,
165    pub unknown_tagged_fields: UnknownTaggedFields,
166}
167
168impl Default for TopicData {
169    fn default() -> Self {
170        Self {
171            topic_id: Default::default(),
172            partitions: Vec::new(),
173            unknown_tagged_fields: Default::default(),
174        }
175    }
176}
177
178impl TopicData {
179    pub fn to_owned(&self) -> crate::owned::assign_replicas_to_dirs_response::TopicData {
180        crate::owned::assign_replicas_to_dirs_response::TopicData {
181            topic_id: (self.topic_id),
182            partitions: (self.partitions).iter().map(|it| it.to_owned()).collect(),
183            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
184        }
185    }
186}
187
188impl Encode for TopicData {
189    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
190        let flex = version >= 0;
191        if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
192        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
193        if flex {
194            let tagged = WriteTaggedFields::new();
195            tagged.write(buf, &self.unknown_tagged_fields);
196        }
197        Ok(())
198    }
199    fn encoded_len(&self, version: i16) -> usize {
200        let flex = version >= 0;
201        let mut n: usize = 0;
202        if version >= 0 { n += 16; }
203        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 }; }
204        if flex {
205            let known_pairs: Vec<(u32, usize)> = Vec::new();
206            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
207        }
208        n
209    }
210}
211
212impl<'de> DecodeBorrow<'de> for TopicData {
213    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
214        let flex = version >= 0;
215        let mut out = Self::default();
216        if version >= 0 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
217        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 }; }
218        if flex {
219            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
220                Ok(false)
221            })?;
222        }
223        Ok(out)
224    }
225}
226
227#[derive(Debug, Clone, PartialEq, Eq)]
228pub struct PartitionData {
229    pub partition_index: i32,
230    pub error_code: i16,
231    pub unknown_tagged_fields: UnknownTaggedFields,
232}
233
234impl Default for PartitionData {
235    fn default() -> Self {
236        Self {
237            partition_index: 0i32,
238            error_code: 0i16,
239            unknown_tagged_fields: Default::default(),
240        }
241    }
242}
243
244impl PartitionData {
245    pub fn to_owned(&self) -> crate::owned::assign_replicas_to_dirs_response::PartitionData {
246        crate::owned::assign_replicas_to_dirs_response::PartitionData {
247            partition_index: (self.partition_index),
248            error_code: (self.error_code),
249            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
250        }
251    }
252}
253
254impl Encode for PartitionData {
255    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
256        let flex = version >= 0;
257        if version >= 0 { put_i32(buf, self.partition_index) }
258        if version >= 0 { put_i16(buf, self.error_code) }
259        if flex {
260            let tagged = WriteTaggedFields::new();
261            tagged.write(buf, &self.unknown_tagged_fields);
262        }
263        Ok(())
264    }
265    fn encoded_len(&self, version: i16) -> usize {
266        let flex = version >= 0;
267        let mut n: usize = 0;
268        if version >= 0 { n += 4; }
269        if version >= 0 { n += 2; }
270        if flex {
271            let known_pairs: Vec<(u32, usize)> = Vec::new();
272            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
273        }
274        n
275    }
276}
277
278impl<'de> DecodeBorrow<'de> for PartitionData {
279    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
280        let flex = version >= 0;
281        let mut out = Self::default();
282        if version >= 0 { out.partition_index = get_i32(buf)?; }
283        if version >= 0 { out.error_code = get_i16(buf)?; }
284        if flex {
285            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
286                Ok(false)
287            })?;
288        }
289        Ok(out)
290    }
291}