Skip to main content

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