krabka_protocol/opt/rustwide/workdir/generated/
AlterReplicaLogDirsResponse.owned.rs1use 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_i16, get_i32, put_i16, 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 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 AlterReplicaLogDirsResponse {
28 pub throttle_time_ms: i32,
29 pub results: Vec<AlterReplicaLogDirTopicResult>,
30 pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl Encode for AlterReplicaLogDirsResponse {
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 put_i32(buf, self.throttle_time_ms);
43 }
44 if version >= 0 {
45 {
46 put_array_len(buf, (self.results).len(), flex)?;
47 for it in &self.results {
48 it.encode(buf, version)?;
49 }
50 }
51 }
52 if flex {
53 let tagged = WriteTaggedFields::new();
54 tagged.write(buf, &self.unknown_tagged_fields)?;
55 }
56 Ok(())
57 }
58 fn encoded_len(&self, version: i16) -> usize {
59 let flex = is_flexible(version);
60 let mut n: usize = 0;
61 if version >= 0 {
62 n += 4;
63 }
64 if version >= 0 {
65 n += {
66 let prefix = array_len_prefix_len((self.results).len(), flex);
67 let body: usize = (self.results)
68 .iter()
69 .map(|it| it.encoded_len(version))
70 .sum();
71 prefix + body
72 };
73 }
74 if flex {
75 let known_pairs: Vec<(u32, usize)> = Vec::new();
76 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
77 }
78 n
79 }
80}
81impl Decode<'_> for AlterReplicaLogDirsResponse {
82 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
83 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
84 return Err(ProtocolError::UnsupportedVersion {
85 api_key: API_KEY,
86 version,
87 });
88 }
89 let flex = is_flexible(version);
90 let mut out = Self::default();
91 if version >= 0 {
92 out.throttle_time_ms = get_i32(buf)?;
93 }
94 if version >= 0 {
95 out.results = {
96 let n = get_array_len(buf, flex)?;
97 let mut v = Vec::with_capacity(n);
98 for _ in 0..n {
99 v.push(AlterReplicaLogDirTopicResult::decode(buf, version)?);
100 }
101 v
102 };
103 }
104 if flex {
105 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
106 }
107 Ok(out)
108 }
109}
110#[cfg(test)]
111impl AlterReplicaLogDirsResponse {
112 #[must_use]
113 pub fn populated(version: i16) -> Self {
114 let mut m = Self::default();
115 if version >= 0 {
116 m.throttle_time_ms = 1i32;
117 }
118 if version >= 0 {
119 m.results = vec![AlterReplicaLogDirTopicResult::populated(version)];
120 }
121 m
122 }
123}
124#[derive(Debug, Clone, PartialEq, Eq, Default)]
125pub struct AlterReplicaLogDirTopicResult {
126 pub topic_name: String,
127 pub partitions: Vec<AlterReplicaLogDirPartitionResult>,
128 pub unknown_tagged_fields: UnknownTaggedFields,
129}
130impl Encode for AlterReplicaLogDirTopicResult {
131 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
132 let flex = version >= 2;
133 if version >= 0 {
134 if flex {
135 put_compact_string(buf, &self.topic_name)?;
136 } else {
137 put_string(buf, &self.topic_name)?;
138 }
139 }
140 if version >= 0 {
141 {
142 put_array_len(buf, (self.partitions).len(), flex)?;
143 for it in &self.partitions {
144 it.encode(buf, version)?;
145 }
146 }
147 }
148 if flex {
149 let tagged = WriteTaggedFields::new();
150 tagged.write(buf, &self.unknown_tagged_fields)?;
151 }
152 Ok(())
153 }
154 fn encoded_len(&self, version: i16) -> usize {
155 let flex = version >= 2;
156 let mut n: usize = 0;
157 if version >= 0 {
158 n += if flex {
159 compact_string_len(&self.topic_name)
160 } else {
161 string_len(&self.topic_name)
162 };
163 }
164 if version >= 0 {
165 n += {
166 let prefix = array_len_prefix_len((self.partitions).len(), flex);
167 let body: usize = (self.partitions)
168 .iter()
169 .map(|it| it.encoded_len(version))
170 .sum();
171 prefix + body
172 };
173 }
174 if flex {
175 let known_pairs: Vec<(u32, usize)> = Vec::new();
176 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
177 }
178 n
179 }
180}
181impl Decode<'_> for AlterReplicaLogDirTopicResult {
182 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
183 let flex = version >= 2;
184 let mut out = Self::default();
185 if version >= 0 {
186 out.topic_name = if flex {
187 get_compact_string_owned(buf)?
188 } else {
189 get_string_owned(buf)?
190 };
191 }
192 if version >= 0 {
193 out.partitions = {
194 let n = get_array_len(buf, flex)?;
195 let mut v = Vec::with_capacity(n);
196 for _ in 0..n {
197 v.push(AlterReplicaLogDirPartitionResult::decode(buf, version)?);
198 }
199 v
200 };
201 }
202 if flex {
203 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
204 }
205 Ok(out)
206 }
207}
208#[cfg(test)]
209impl AlterReplicaLogDirTopicResult {
210 #[must_use]
211 pub fn populated(version: i16) -> Self {
212 let mut m = Self::default();
213 if version >= 0 {
214 m.topic_name = "x".to_owned();
215 }
216 if version >= 0 {
217 m.partitions = vec![AlterReplicaLogDirPartitionResult::populated(version)];
218 }
219 m
220 }
221}
222#[derive(Debug, Clone, PartialEq, Eq, Default)]
223pub struct AlterReplicaLogDirPartitionResult {
224 pub partition_index: i32,
225 pub error_code: i16,
226 pub unknown_tagged_fields: UnknownTaggedFields,
227}
228impl Encode for AlterReplicaLogDirPartitionResult {
229 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
230 let flex = version >= 2;
231 if version >= 0 {
232 put_i32(buf, self.partition_index);
233 }
234 if version >= 0 {
235 put_i16(buf, self.error_code);
236 }
237 if flex {
238 let tagged = WriteTaggedFields::new();
239 tagged.write(buf, &self.unknown_tagged_fields)?;
240 }
241 Ok(())
242 }
243 fn encoded_len(&self, version: i16) -> usize {
244 let flex = version >= 2;
245 let mut n: usize = 0;
246 if version >= 0 {
247 n += 4;
248 }
249 if version >= 0 {
250 n += 2;
251 }
252 if flex {
253 let known_pairs: Vec<(u32, usize)> = Vec::new();
254 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
255 }
256 n
257 }
258}
259impl Decode<'_> for AlterReplicaLogDirPartitionResult {
260 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
261 let flex = version >= 2;
262 let mut out = Self::default();
263 if version >= 0 {
264 out.partition_index = get_i32(buf)?;
265 }
266 if version >= 0 {
267 out.error_code = get_i16(buf)?;
268 }
269 if flex {
270 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
271 }
272 Ok(out)
273 }
274}
275#[cfg(test)]
276impl AlterReplicaLogDirPartitionResult {
277 #[must_use]
278 pub fn populated(version: i16) -> Self {
279 let mut m = Self::default();
280 if version >= 0 {
281 m.partition_index = 1i32;
282 }
283 if version >= 0 {
284 m.error_code = 1i16;
285 }
286 m
287 }
288}
289#[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_owned(), ::serde_json::json!(0));
296 obj.insert("results".to_owned(), ::serde_json::Value::Array(vec![]));
297 ::serde_json::Value::Object(obj)
298}