Skip to main content

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

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