Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AssignReplicasToDirsRequest.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{get_i32, get_i64, put_i32, put_i64};
4use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
5use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
6use bytes::{Buf, BufMut};
7pub const API_KEY: i16 = 73;
8pub const MIN_VERSION: i16 = 0;
9pub const MAX_VERSION: i16 = 0;
10pub const FLEXIBLE_MIN: i16 = 0;
11#[inline]
12fn is_flexible(version: i16) -> bool {
13    version >= FLEXIBLE_MIN
14}
15#[derive(Debug, Clone, PartialEq, Eq)]
16pub struct AssignReplicasToDirsRequest {
17    pub broker_id: i32,
18    pub broker_epoch: i64,
19    pub directories: Vec<DirectoryData>,
20    pub unknown_tagged_fields: UnknownTaggedFields,
21}
22impl Default for AssignReplicasToDirsRequest {
23    fn default() -> Self {
24        Self {
25            broker_id: 0i32,
26            broker_epoch: -1i64,
27            directories: Vec::new(),
28            unknown_tagged_fields: Default::default(),
29        }
30    }
31}
32impl Encode for AssignReplicasToDirsRequest {
33    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
34        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
35            return Err(ProtocolError::UnsupportedVersion {
36                api_key: API_KEY,
37                version,
38            });
39        }
40        let flex = is_flexible(version);
41        if version >= 0 {
42            put_i32(buf, self.broker_id);
43        }
44        if version >= 0 {
45            put_i64(buf, self.broker_epoch);
46        }
47        if version >= 0 {
48            {
49                crate::primitives::array::put_array_len(buf, (self.directories).len(), flex);
50                for it in &self.directories {
51                    it.encode(buf, version)?;
52                }
53            }
54        }
55        if flex {
56            let tagged = WriteTaggedFields::new();
57            tagged.write(buf, &self.unknown_tagged_fields);
58        }
59        Ok(())
60    }
61    fn encoded_len(&self, version: i16) -> usize {
62        let flex = is_flexible(version);
63        let mut n: usize = 0;
64        if version >= 0 {
65            n += 4;
66        }
67        if version >= 0 {
68            n += 8;
69        }
70        if version >= 0 {
71            n += {
72                let prefix =
73                    crate::primitives::array::array_len_prefix_len((self.directories).len(), flex);
74                let body: usize = (self.directories)
75                    .iter()
76                    .map(|it| it.encoded_len(version))
77                    .sum();
78                prefix + body
79            };
80        }
81        if flex {
82            let known_pairs: Vec<(u32, usize)> = Vec::new();
83            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
84        }
85        n
86    }
87}
88impl Decode<'_> for AssignReplicasToDirsRequest {
89    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
90        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
91            return Err(ProtocolError::UnsupportedVersion {
92                api_key: API_KEY,
93                version,
94            });
95        }
96        let flex = is_flexible(version);
97        let mut out = Self::default();
98        if version >= 0 {
99            out.broker_id = get_i32(buf)?;
100        }
101        if version >= 0 {
102            out.broker_epoch = get_i64(buf)?;
103        }
104        if version >= 0 {
105            out.directories = {
106                let n = crate::primitives::array::get_array_len(buf, flex)?;
107                let mut v = Vec::with_capacity(n);
108                for _ in 0..n {
109                    v.push(DirectoryData::decode(buf, version)?);
110                }
111                v
112            };
113        }
114        if flex {
115            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
116        }
117        Ok(out)
118    }
119}
120#[cfg(test)]
121impl AssignReplicasToDirsRequest {
122    #[must_use]
123    pub fn populated(version: i16) -> Self {
124        let mut m = Self::default();
125        if version >= 0 {
126            m.broker_id = 1i32;
127        }
128        if version >= 0 {
129            m.broker_epoch = 1i64;
130        }
131        if version >= 0 {
132            m.directories = vec![DirectoryData::populated(version)];
133        }
134        m
135    }
136}
137#[derive(Debug, Clone, PartialEq, Eq, Default)]
138pub struct DirectoryData {
139    pub id: crate::primitives::uuid::Uuid,
140    pub topics: Vec<TopicData>,
141    pub unknown_tagged_fields: UnknownTaggedFields,
142}
143impl Encode for DirectoryData {
144    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
145        let flex = version >= 0;
146        if version >= 0 {
147            crate::primitives::uuid::put_uuid(buf, self.id);
148        }
149        if version >= 0 {
150            {
151                crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
152                for it in &self.topics {
153                    it.encode(buf, version)?;
154                }
155            }
156        }
157        if flex {
158            let tagged = WriteTaggedFields::new();
159            tagged.write(buf, &self.unknown_tagged_fields);
160        }
161        Ok(())
162    }
163    fn encoded_len(&self, version: i16) -> usize {
164        let flex = version >= 0;
165        let mut n: usize = 0;
166        if version >= 0 {
167            n += 16;
168        }
169        if version >= 0 {
170            n += {
171                let prefix =
172                    crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
173                let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
174                prefix + body
175            };
176        }
177        if flex {
178            let known_pairs: Vec<(u32, usize)> = Vec::new();
179            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
180        }
181        n
182    }
183}
184impl Decode<'_> for DirectoryData {
185    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
186        let flex = version >= 0;
187        let mut out = Self::default();
188        if version >= 0 {
189            out.id = crate::primitives::uuid::get_uuid(buf)?;
190        }
191        if version >= 0 {
192            out.topics = {
193                let n = crate::primitives::array::get_array_len(buf, flex)?;
194                let mut v = Vec::with_capacity(n);
195                for _ in 0..n {
196                    v.push(TopicData::decode(buf, version)?);
197                }
198                v
199            };
200        }
201        if flex {
202            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
203        }
204        Ok(out)
205    }
206}
207#[cfg(test)]
208impl DirectoryData {
209    #[must_use]
210    pub fn populated(version: i16) -> Self {
211        let mut m = Self::default();
212        if version >= 0 {
213            m.id = crate::primitives::uuid::Uuid([1u8; 16]);
214        }
215        if version >= 0 {
216            m.topics = vec![TopicData::populated(version)];
217        }
218        m
219    }
220}
221#[derive(Debug, Clone, PartialEq, Eq, Default)]
222pub struct TopicData {
223    pub topic_id: crate::primitives::uuid::Uuid,
224    pub partitions: Vec<PartitionData>,
225    pub unknown_tagged_fields: UnknownTaggedFields,
226}
227impl Encode for TopicData {
228    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
229        let flex = version >= 0;
230        if version >= 0 {
231            crate::primitives::uuid::put_uuid(buf, self.topic_id);
232        }
233        if version >= 0 {
234            {
235                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
236                for it in &self.partitions {
237                    it.encode(buf, version)?;
238                }
239            }
240        }
241        if flex {
242            let tagged = WriteTaggedFields::new();
243            tagged.write(buf, &self.unknown_tagged_fields);
244        }
245        Ok(())
246    }
247    fn encoded_len(&self, version: i16) -> usize {
248        let flex = version >= 0;
249        let mut n: usize = 0;
250        if version >= 0 {
251            n += 16;
252        }
253        if version >= 0 {
254            n += {
255                let prefix =
256                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
257                let body: usize = (self.partitions)
258                    .iter()
259                    .map(|it| it.encoded_len(version))
260                    .sum();
261                prefix + body
262            };
263        }
264        if flex {
265            let known_pairs: Vec<(u32, usize)> = Vec::new();
266            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
267        }
268        n
269    }
270}
271impl Decode<'_> for TopicData {
272    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
273        let flex = version >= 0;
274        let mut out = Self::default();
275        if version >= 0 {
276            out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
277        }
278        if version >= 0 {
279            out.partitions = {
280                let n = crate::primitives::array::get_array_len(buf, flex)?;
281                let mut v = Vec::with_capacity(n);
282                for _ in 0..n {
283                    v.push(PartitionData::decode(buf, version)?);
284                }
285                v
286            };
287        }
288        if flex {
289            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
290        }
291        Ok(out)
292    }
293}
294#[cfg(test)]
295impl TopicData {
296    #[must_use]
297    pub fn populated(version: i16) -> Self {
298        let mut m = Self::default();
299        if version >= 0 {
300            m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
301        }
302        if version >= 0 {
303            m.partitions = vec![PartitionData::populated(version)];
304        }
305        m
306    }
307}
308#[derive(Debug, Clone, PartialEq, Eq, Default)]
309pub struct PartitionData {
310    pub partition_index: i32,
311    pub unknown_tagged_fields: UnknownTaggedFields,
312}
313impl Encode for PartitionData {
314    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
315        let flex = version >= 0;
316        if version >= 0 {
317            put_i32(buf, self.partition_index);
318        }
319        if flex {
320            let tagged = WriteTaggedFields::new();
321            tagged.write(buf, &self.unknown_tagged_fields);
322        }
323        Ok(())
324    }
325    fn encoded_len(&self, version: i16) -> usize {
326        let flex = version >= 0;
327        let mut n: usize = 0;
328        if version >= 0 {
329            n += 4;
330        }
331        if flex {
332            let known_pairs: Vec<(u32, usize)> = Vec::new();
333            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
334        }
335        n
336    }
337}
338impl Decode<'_> for PartitionData {
339    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
340        let flex = version >= 0;
341        let mut out = Self::default();
342        if version >= 0 {
343            out.partition_index = get_i32(buf)?;
344        }
345        if flex {
346            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
347        }
348        Ok(out)
349    }
350}
351#[cfg(test)]
352impl PartitionData {
353    #[must_use]
354    pub fn populated(version: i16) -> Self {
355        let mut m = Self::default();
356        if version >= 0 {
357            m.partition_index = 1i32;
358        }
359        m
360    }
361}
362/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
363/// Only includes fields valid for the given version.
364#[must_use]
365#[allow(unused_comparisons)]
366pub fn default_json(version: i16) -> ::serde_json::Value {
367    let mut obj = ::serde_json::Map::new();
368    obj.insert("brokerId".to_string(), ::serde_json::json!(0));
369    obj.insert("brokerEpoch".to_string(), ::serde_json::json!(-1));
370    obj.insert(
371        "directories".to_string(),
372        ::serde_json::Value::Array(vec![]),
373    );
374    ::serde_json::Value::Object(obj)
375}
376impl crate::ProtocolRequest for AssignReplicasToDirsRequest {
377    const API_KEY: i16 = API_KEY;
378    const MIN_VERSION: i16 = MIN_VERSION;
379    const MAX_VERSION: i16 = MAX_VERSION;
380    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
381    type Response = super::assign_replicas_to_dirs_response::AssignReplicasToDirsResponse;
382}