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