Skip to main content

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

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