Skip to main content

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