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