Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AlterReplicaLogDirsResponse.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::primitives::string_bytes::{
7    compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
8    string_len,
9};
10use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 34;
14pub const MIN_VERSION: i16 = 1;
15pub const MAX_VERSION: i16 = 2;
16pub const FLEXIBLE_MIN: i16 = 2;
17
18#[inline]
19fn is_flexible(version: i16) -> bool {
20    version >= FLEXIBLE_MIN
21}
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct AlterReplicaLogDirsResponse {
25    pub throttle_time_ms: i32,
26    pub results: Vec<AlterReplicaLogDirTopicResult>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29impl Encode for AlterReplicaLogDirsResponse {
30    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
31        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
32            return Err(ProtocolError::UnsupportedVersion {
33                api_key: API_KEY,
34                version,
35            });
36        }
37        let flex = is_flexible(version);
38        if version >= 0 {
39            put_i32(buf, self.throttle_time_ms);
40        }
41        if version >= 0 {
42            {
43                crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
44                for it in &self.results {
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 += {
63                let prefix =
64                    crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
65                let body: usize = (self.results)
66                    .iter()
67                    .map(|it| it.encoded_len(version))
68                    .sum();
69                prefix + body
70            };
71        }
72        if flex {
73            let known_pairs: Vec<(u32, usize)> = Vec::new();
74            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
75        }
76        n
77    }
78}
79impl Decode<'_> for AlterReplicaLogDirsResponse {
80    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
81        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
82            return Err(ProtocolError::UnsupportedVersion {
83                api_key: API_KEY,
84                version,
85            });
86        }
87        let flex = is_flexible(version);
88        let mut out = Self::default();
89        if version >= 0 {
90            out.throttle_time_ms = get_i32(buf)?;
91        }
92        if version >= 0 {
93            out.results = {
94                let n = crate::primitives::array::get_array_len(buf, flex)?;
95                let mut v = Vec::with_capacity(n);
96                for _ in 0..n {
97                    v.push(AlterReplicaLogDirTopicResult::decode(buf, version)?);
98                }
99                v
100            };
101        }
102        if flex {
103            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
104        }
105        Ok(out)
106    }
107}
108#[cfg(test)]
109impl AlterReplicaLogDirsResponse {
110    #[must_use]
111    pub fn populated(version: i16) -> Self {
112        let mut m = Self::default();
113        if version >= 0 {
114            m.throttle_time_ms = 1i32;
115        }
116        if version >= 0 {
117            m.results = vec![AlterReplicaLogDirTopicResult::populated(version)];
118        }
119        m
120    }
121}
122#[derive(Debug, Clone, PartialEq, Eq, Default)]
123pub struct AlterReplicaLogDirTopicResult {
124    pub topic_name: String,
125    pub partitions: Vec<AlterReplicaLogDirPartitionResult>,
126    pub unknown_tagged_fields: UnknownTaggedFields,
127}
128impl Encode for AlterReplicaLogDirTopicResult {
129    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
130        let flex = version >= 2;
131        if version >= 0 {
132            if flex {
133                put_compact_string(buf, &self.topic_name);
134            } else {
135                put_string(buf, &self.topic_name);
136            }
137        }
138        if version >= 0 {
139            {
140                crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
141                for it in &self.partitions {
142                    it.encode(buf, version)?;
143                }
144            }
145        }
146        if flex {
147            let tagged = WriteTaggedFields::new();
148            tagged.write(buf, &self.unknown_tagged_fields);
149        }
150        Ok(())
151    }
152    fn encoded_len(&self, version: i16) -> usize {
153        let flex = version >= 2;
154        let mut n: usize = 0;
155        if version >= 0 {
156            n += if flex {
157                compact_string_len(&self.topic_name)
158            } else {
159                string_len(&self.topic_name)
160            };
161        }
162        if version >= 0 {
163            n += {
164                let prefix =
165                    crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
166                let body: usize = (self.partitions)
167                    .iter()
168                    .map(|it| it.encoded_len(version))
169                    .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 AlterReplicaLogDirTopicResult {
181    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
182        let flex = version >= 2;
183        let mut out = Self::default();
184        if version >= 0 {
185            out.topic_name = if flex {
186                get_compact_string_owned(buf)?
187            } else {
188                get_string_owned(buf)?
189            };
190        }
191        if version >= 0 {
192            out.partitions = {
193                let n = crate::primitives::array::get_array_len(buf, flex)?;
194                let mut v = Vec::with_capacity(n);
195                for _ in 0..n {
196                    v.push(AlterReplicaLogDirPartitionResult::decode(buf, version)?);
197                }
198                v
199            };
200        }
201        if flex {
202            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
203        }
204        Ok(out)
205    }
206}
207#[cfg(test)]
208impl AlterReplicaLogDirTopicResult {
209    #[must_use]
210    pub fn populated(version: i16) -> Self {
211        let mut m = Self::default();
212        if version >= 0 {
213            m.topic_name = "x".to_string();
214        }
215        if version >= 0 {
216            m.partitions = vec![AlterReplicaLogDirPartitionResult::populated(version)];
217        }
218        m
219    }
220}
221#[derive(Debug, Clone, PartialEq, Eq, Default)]
222pub struct AlterReplicaLogDirPartitionResult {
223    pub partition_index: i32,
224    pub error_code: i16,
225    pub unknown_tagged_fields: UnknownTaggedFields,
226}
227impl Encode for AlterReplicaLogDirPartitionResult {
228    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
229        let flex = version >= 2;
230        if version >= 0 {
231            put_i32(buf, self.partition_index);
232        }
233        if version >= 0 {
234            put_i16(buf, self.error_code);
235        }
236        if flex {
237            let tagged = WriteTaggedFields::new();
238            tagged.write(buf, &self.unknown_tagged_fields);
239        }
240        Ok(())
241    }
242    fn encoded_len(&self, version: i16) -> usize {
243        let flex = version >= 2;
244        let mut n: usize = 0;
245        if version >= 0 {
246            n += 4;
247        }
248        if version >= 0 {
249            n += 2;
250        }
251        if flex {
252            let known_pairs: Vec<(u32, usize)> = Vec::new();
253            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
254        }
255        n
256    }
257}
258impl Decode<'_> for AlterReplicaLogDirPartitionResult {
259    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
260        let flex = version >= 2;
261        let mut out = Self::default();
262        if version >= 0 {
263            out.partition_index = get_i32(buf)?;
264        }
265        if version >= 0 {
266            out.error_code = get_i16(buf)?;
267        }
268        if flex {
269            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
270        }
271        Ok(out)
272    }
273}
274#[cfg(test)]
275impl AlterReplicaLogDirPartitionResult {
276    #[must_use]
277    pub fn populated(version: i16) -> Self {
278        let mut m = Self::default();
279        if version >= 0 {
280            m.partition_index = 1i32;
281        }
282        if version >= 0 {
283            m.error_code = 1i16;
284        }
285        m
286    }
287}
288
289/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
290/// Only includes fields valid for the given version.
291#[must_use]
292#[allow(unused_comparisons)]
293pub fn default_json(version: i16) -> ::serde_json::Value {
294    let mut obj = ::serde_json::Map::new();
295    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
296    obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
297    ::serde_json::Value::Object(obj)
298}