krabka_protocol/opt/rustwide/workdir/generated/
AlterReplicaLogDirsRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 fixed::{get_i32, put_i32},
9 string_bytes::{
10 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
11 put_string, string_len,
12 },
13 },
14 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
15};
16pub const API_KEY: i16 = 34;
17pub const MIN_VERSION: i16 = 1;
18pub const MAX_VERSION: i16 = 2;
19pub const LATEST_STABLE_VERSION: i16 = 2;
20pub const FLEXIBLE_MIN: i16 = 2;
21#[inline]
22#[must_use]
23pub fn is_flexible(version: i16) -> bool {
24 version >= FLEXIBLE_MIN
25}
26#[derive(Debug, Clone, PartialEq, Eq, Default)]
27pub struct AlterReplicaLogDirsRequest {
28 pub dirs: Vec<AlterReplicaLogDir>,
29 pub unknown_tagged_fields: UnknownTaggedFields,
30}
31impl Encode for AlterReplicaLogDirsRequest {
32 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
33 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
34 return Err(ProtocolError::UnsupportedVersion {
35 api_key: API_KEY,
36 version,
37 });
38 }
39 let flex = is_flexible(version);
40 if version >= 0 {
41 {
42 crate::primitives::array::put_array_len(buf, (self.dirs).len(), flex);
43 for it in &self.dirs {
44 it.encode(buf, version)?;
45 }
46 };
47 }
48 if flex {
49 let tagged = WriteTaggedFields::new();
50 tagged.write(buf, &self.unknown_tagged_fields);
51 }
52 Ok(())
53 }
54 fn encoded_len(&self, version: i16) -> usize {
55 let flex = is_flexible(version);
56 let mut n: usize = 0;
57 if version >= 0 {
58 n += {
59 let prefix =
60 crate::primitives::array::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 = crate::primitives::array::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 let () = put_compact_string(buf, &self.path);
121 } else {
122 let () = put_string(buf, &self.path);
123 }
124 }
125 if version >= 0 {
126 {
127 crate::primitives::array::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 =
152 crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
153 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
154 prefix + body
155 };
156 }
157 if flex {
158 let known_pairs: Vec<(u32, usize)> = Vec::new();
159 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
160 }
161 n
162 }
163}
164impl Decode<'_> for AlterReplicaLogDir {
165 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
166 let flex = version >= 2;
167 let mut out = Self::default();
168 if version >= 0 {
169 out.path = if flex {
170 get_compact_string_owned(buf)?
171 } else {
172 get_string_owned(buf)?
173 };
174 }
175 if version >= 0 {
176 out.topics = {
177 let n = crate::primitives::array::get_array_len(buf, flex)?;
178 let mut v = Vec::with_capacity(n);
179 for _ in 0..n {
180 v.push(AlterReplicaLogDirTopic::decode(buf, version)?);
181 }
182 v
183 };
184 }
185 if flex {
186 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
187 }
188 Ok(out)
189 }
190}
191#[cfg(test)]
192impl AlterReplicaLogDir {
193 #[must_use]
194 pub fn populated(version: i16) -> Self {
195 let mut m = Self::default();
196 if version >= 0 {
197 m.path = "x".to_string();
198 }
199 if version >= 0 {
200 m.topics = vec![AlterReplicaLogDirTopic::populated(version)];
201 }
202 m
203 }
204}
205#[derive(Debug, Clone, PartialEq, Eq, Default)]
206pub struct AlterReplicaLogDirTopic {
207 pub name: String,
208 pub partitions: Vec<i32>,
209 pub unknown_tagged_fields: UnknownTaggedFields,
210}
211impl Encode for AlterReplicaLogDirTopic {
212 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
213 let flex = version >= 2;
214 if version >= 0 {
215 if flex {
216 let () = put_compact_string(buf, &self.name);
217 } else {
218 let () = put_string(buf, &self.name);
219 }
220 }
221 if version >= 0 {
222 {
223 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
224 for it in &self.partitions {
225 put_i32(buf, *it);
226 }
227 };
228 }
229 if flex {
230 let tagged = WriteTaggedFields::new();
231 tagged.write(buf, &self.unknown_tagged_fields);
232 }
233 Ok(())
234 }
235 fn encoded_len(&self, version: i16) -> usize {
236 let flex = version >= 2;
237 let mut n: usize = 0;
238 if version >= 0 {
239 n += if flex {
240 compact_string_len(&self.name)
241 } else {
242 string_len(&self.name)
243 };
244 }
245 if version >= 0 {
246 n += {
247 let prefix =
248 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
249 let body: usize = (self.partitions).iter().map(|_| 4).sum();
250 prefix + body
251 };
252 }
253 if flex {
254 let known_pairs: Vec<(u32, usize)> = Vec::new();
255 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
256 }
257 n
258 }
259}
260impl Decode<'_> for AlterReplicaLogDirTopic {
261 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
262 let flex = version >= 2;
263 let mut out = Self::default();
264 if version >= 0 {
265 out.name = if flex {
266 get_compact_string_owned(buf)?
267 } else {
268 get_string_owned(buf)?
269 };
270 }
271 if version >= 0 {
272 out.partitions = {
273 let n = crate::primitives::array::get_array_len(buf, flex)?;
274 let mut v = Vec::with_capacity(n);
275 for _ in 0..n {
276 v.push(get_i32(buf)?);
277 }
278 v
279 };
280 }
281 if flex {
282 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
283 }
284 Ok(out)
285 }
286}
287#[cfg(test)]
288impl AlterReplicaLogDirTopic {
289 #[must_use]
290 pub fn populated(version: i16) -> Self {
291 let mut m = Self::default();
292 if version >= 0 {
293 m.name = "x".to_string();
294 }
295 if version >= 0 {
296 m.partitions = vec![1i32];
297 }
298 m
299 }
300}
301#[must_use]
304#[allow(unused_comparisons)]
305pub fn default_json(_version: i16) -> ::serde_json::Value {
306 let mut obj = ::serde_json::Map::new();
307 obj.insert("dirs".to_string(), ::serde_json::Value::Array(vec![]));
308 ::serde_json::Value::Object(obj)
309}
310impl crate::ProtocolRequest for AlterReplicaLogDirsRequest {
311 const API_KEY: i16 = API_KEY;
312 const MIN_VERSION: i16 = MIN_VERSION;
313 const MAX_VERSION: i16 = MAX_VERSION;
314 const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
315 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
316 type Response = super::alter_replica_log_dirs_response::AlterReplicaLogDirsResponse;
317}