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::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
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 { version >= FLEXIBLE_MIN }
16
17#[derive(Debug, Clone, PartialEq, Eq, Default)]
18pub struct AssignReplicasToDirsResponse {
19    pub throttle_time_ms: i32,
20    pub error_code: i16,
21    pub directories: Vec<DirectoryData>,
22    pub unknown_tagged_fields: UnknownTaggedFields,
23}
24
25impl Encode for AssignReplicasToDirsResponse {
26    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
27        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
28            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
29        }
30        let flex = is_flexible(version);
31        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
32        if version >= 0 { put_i16(buf, self.error_code) }
33        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.directories).len(), flex); for it in &self.directories { it.encode(buf, version)?; } } }
34        if flex {
35            let tagged = WriteTaggedFields::new();
36            tagged.write(buf, &self.unknown_tagged_fields);
37        }
38        Ok(())
39    }
40    fn encoded_len(&self, version: i16) -> usize {
41        let flex = is_flexible(version);
42        let mut n: usize = 0;
43        if version >= 0 { n += 4; }
44        if version >= 0 { n += 2; }
45        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.directories).len(), flex); let body: usize = (self.directories).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
46        if flex {
47            let known_pairs: Vec<(u32, usize)> = Vec::new();
48            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
49        }
50        n
51    }
52}
53
54impl<'de> Decode<'de> for AssignReplicasToDirsResponse {
55    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
56        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
57            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
58        }
59        let flex = is_flexible(version);
60        let mut out = Self::default();
61        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
62        if version >= 0 { out.error_code = get_i16(buf)?; }
63        if version >= 0 { out.directories = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DirectoryData::decode(buf, version)?); } v }; }
64        if flex {
65            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
66                Ok(false)
67            })?;
68        }
69        Ok(out)
70    }
71}
72
73#[derive(Debug, Clone, PartialEq, Eq, Default)]
74pub struct DirectoryData {
75    pub id: crate::primitives::uuid::Uuid,
76    pub topics: Vec<TopicData>,
77    pub unknown_tagged_fields: UnknownTaggedFields,
78}
79
80impl Encode for DirectoryData {
81    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
82        let flex = version >= 0;
83        if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.id) }
84        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
85        if flex {
86            let tagged = WriteTaggedFields::new();
87            tagged.write(buf, &self.unknown_tagged_fields);
88        }
89        Ok(())
90    }
91    fn encoded_len(&self, version: i16) -> usize {
92        let flex = version >= 0;
93        let mut n: usize = 0;
94        if version >= 0 { n += 16; }
95        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topics).len(), flex); let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
96        if flex {
97            let known_pairs: Vec<(u32, usize)> = Vec::new();
98            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
99        }
100        n
101    }
102}
103
104impl<'de> Decode<'de> for DirectoryData {
105    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
106        let flex = version >= 0;
107        let mut out = Self::default();
108        if version >= 0 { out.id = crate::primitives::uuid::get_uuid(buf)?; }
109        if version >= 0 { out.topics = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(TopicData::decode(buf, version)?); } v }; }
110        if flex {
111            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
112                Ok(false)
113            })?;
114        }
115        Ok(out)
116    }
117}
118
119#[derive(Debug, Clone, PartialEq, Eq, Default)]
120pub struct TopicData {
121    pub topic_id: crate::primitives::uuid::Uuid,
122    pub partitions: Vec<PartitionData>,
123    pub unknown_tagged_fields: UnknownTaggedFields,
124}
125
126impl Encode for TopicData {
127    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
128        let flex = version >= 0;
129        if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
130        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
131        if flex {
132            let tagged = WriteTaggedFields::new();
133            tagged.write(buf, &self.unknown_tagged_fields);
134        }
135        Ok(())
136    }
137    fn encoded_len(&self, version: i16) -> usize {
138        let flex = version >= 0;
139        let mut n: usize = 0;
140        if version >= 0 { n += 16; }
141        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex); let body: usize = (self.partitions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
142        if flex {
143            let known_pairs: Vec<(u32, usize)> = Vec::new();
144            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
145        }
146        n
147    }
148}
149
150impl<'de> Decode<'de> for TopicData {
151    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
152        let flex = version >= 0;
153        let mut out = Self::default();
154        if version >= 0 { out.topic_id = crate::primitives::uuid::get_uuid(buf)?; }
155        if version >= 0 { out.partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(PartitionData::decode(buf, version)?); } v }; }
156        if flex {
157            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
158                Ok(false)
159            })?;
160        }
161        Ok(out)
162    }
163}
164
165#[derive(Debug, Clone, PartialEq, Eq, Default)]
166pub struct PartitionData {
167    pub partition_index: i32,
168    pub error_code: i16,
169    pub unknown_tagged_fields: UnknownTaggedFields,
170}
171
172impl Encode for PartitionData {
173    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
174        let flex = version >= 0;
175        if version >= 0 { put_i32(buf, self.partition_index) }
176        if version >= 0 { put_i16(buf, self.error_code) }
177        if flex {
178            let tagged = WriteTaggedFields::new();
179            tagged.write(buf, &self.unknown_tagged_fields);
180        }
181        Ok(())
182    }
183    fn encoded_len(&self, version: i16) -> usize {
184        let flex = version >= 0;
185        let mut n: usize = 0;
186        if version >= 0 { n += 4; }
187        if version >= 0 { n += 2; }
188        if flex {
189            let known_pairs: Vec<(u32, usize)> = Vec::new();
190            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
191        }
192        n
193    }
194}
195
196impl<'de> Decode<'de> for PartitionData {
197    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
198        let flex = version >= 0;
199        let mut out = Self::default();
200        if version >= 0 { out.partition_index = get_i32(buf)?; }
201        if version >= 0 { out.error_code = get_i16(buf)?; }
202        if flex {
203            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
204                Ok(false)
205            })?;
206        }
207        Ok(out)
208    }
209}
210
211/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
212/// Only includes fields valid for the given version.
213#[must_use]
214#[allow(unused_comparisons)]
215pub fn default_json(version: i16) -> ::serde_json::Value {
216    let mut obj = ::serde_json::Map::new();
217    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
218    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
219    obj.insert("directories".to_string(), ::serde_json::Value::Array(vec![]));
220    ::serde_json::Value::Object(obj)
221}