crabka_protocol/opt/rustwide/workdir/generated/
AssignReplicasToDirsRequest.borrowed.rs1use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i32, get_i64, put_i32, put_i64};
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 AssignReplicasToDirsRequest {
19 pub broker_id: i32,
20 pub broker_epoch: i64,
21 pub directories: Vec<DirectoryData>,
22 pub unknown_tagged_fields: UnknownTaggedFields,
23}
24
25impl Default for AssignReplicasToDirsRequest {
26 fn default() -> Self {
27 Self {
28 broker_id: 0i32,
29 broker_epoch: -1i64,
30 directories: Vec::new(),
31 unknown_tagged_fields: Default::default(),
32 }
33 }
34}
35
36impl AssignReplicasToDirsRequest {
37 pub fn to_owned(&self) -> crate::owned::assign_replicas_to_dirs_request::AssignReplicasToDirsRequest {
38 crate::owned::assign_replicas_to_dirs_request::AssignReplicasToDirsRequest {
39 broker_id: (self.broker_id),
40 broker_epoch: (self.broker_epoch),
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 AssignReplicasToDirsRequest {
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.broker_id) }
54 if version >= 0 { put_i64(buf, self.broker_epoch) }
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 += 8; }
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 AssignReplicasToDirsRequest {
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.broker_id = get_i32(buf)?; }
84 if version >= 0 { out.broker_epoch = get_i64(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_request::DirectoryData {
114 crate::owned::assign_replicas_to_dirs_request::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_request::TopicData {
180 crate::owned::assign_replicas_to_dirs_request::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 unknown_tagged_fields: UnknownTaggedFields,
231}
232
233impl Default for PartitionData {
234 fn default() -> Self {
235 Self {
236 partition_index: 0i32,
237 unknown_tagged_fields: Default::default(),
238 }
239 }
240}
241
242impl PartitionData {
243 pub fn to_owned(&self) -> crate::owned::assign_replicas_to_dirs_request::PartitionData {
244 crate::owned::assign_replicas_to_dirs_request::PartitionData {
245 partition_index: (self.partition_index),
246 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
247 }
248 }
249}
250
251impl Encode for PartitionData {
252 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
253 let flex = version >= 0;
254 if version >= 0 { put_i32(buf, self.partition_index) }
255 if flex {
256 let tagged = WriteTaggedFields::new();
257 tagged.write(buf, &self.unknown_tagged_fields);
258 }
259 Ok(())
260 }
261 fn encoded_len(&self, version: i16) -> usize {
262 let flex = version >= 0;
263 let mut n: usize = 0;
264 if version >= 0 { n += 4; }
265 if flex {
266 let known_pairs: Vec<(u32, usize)> = Vec::new();
267 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
268 }
269 n
270 }
271}
272
273impl<'de> DecodeBorrow<'de> for PartitionData {
274 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
275 let flex = version >= 0;
276 let mut out = Self::default();
277 if version >= 0 { out.partition_index = get_i32(buf)?; }
278 if flex {
279 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
280 Ok(false)
281 })?;
282 }
283 Ok(out)
284 }
285}