crabka_protocol/opt/rustwide/workdir/generated/
ListPartitionReassignmentsRequest.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 = 46;
12pub const MIN_VERSION: i16 = 0;
13pub const MAX_VERSION: i16 = 0;
14pub const FLEXIBLE_MIN: i16 = 0;
15#[inline]
16fn is_flexible(version: i16) -> bool {
17 version >= FLEXIBLE_MIN
18}
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub struct ListPartitionReassignmentsRequest {
21 pub timeout_ms: i32,
22 pub topics: Option<Vec<ListPartitionReassignmentsTopics>>,
23 pub unknown_tagged_fields: UnknownTaggedFields,
24}
25impl Default for ListPartitionReassignmentsRequest {
26 fn default() -> Self {
27 Self {
28 timeout_ms: 60_000i32,
29 topics: None,
30 unknown_tagged_fields: Default::default(),
31 }
32 }
33}
34impl Encode for ListPartitionReassignmentsRequest {
35 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
36 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
37 return Err(ProtocolError::UnsupportedVersion {
38 api_key: API_KEY,
39 version,
40 });
41 }
42 let flex = is_flexible(version);
43 if version >= 0 {
44 put_i32(buf, self.timeout_ms);
45 }
46 if version >= 0 {
47 {
48 let len = (self.topics).as_ref().map(Vec::len);
49 crate::primitives::array::put_nullable_array_len(buf, len, flex);
50 if let Some(v) = &self.topics {
51 for it in v {
52 it.encode(buf, version)?;
53 }
54 }
55 }
56 }
57 if flex {
58 let tagged = WriteTaggedFields::new();
59 tagged.write(buf, &self.unknown_tagged_fields);
60 }
61 Ok(())
62 }
63 fn encoded_len(&self, version: i16) -> usize {
64 let flex = is_flexible(version);
65 let mut n: usize = 0;
66 if version >= 0 {
67 n += 4;
68 }
69 if version >= 0 {
70 n += {
71 let opt: Option<&Vec<_>> = (self.topics).as_ref();
72 let prefix = crate::primitives::array::nullable_array_len_prefix_len(
73 opt.map(std::vec::Vec::len),
74 flex,
75 );
76 let body: usize =
77 opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
78 prefix + body
79 };
80 }
81 if flex {
82 let known_pairs: Vec<(u32, usize)> = Vec::new();
83 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
84 }
85 n
86 }
87}
88impl Decode<'_> for ListPartitionReassignmentsRequest {
89 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
90 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
91 return Err(ProtocolError::UnsupportedVersion {
92 api_key: API_KEY,
93 version,
94 });
95 }
96 let flex = is_flexible(version);
97 let mut out = Self::default();
98 if version >= 0 {
99 out.timeout_ms = get_i32(buf)?;
100 }
101 if version >= 0 {
102 out.topics = {
103 let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
104 match opt {
105 None => None,
106 Some(n) => {
107 let mut v = Vec::with_capacity(n);
108 for _ in 0..n {
109 v.push(ListPartitionReassignmentsTopics::decode(buf, version)?);
110 }
111 Some(v)
112 }
113 }
114 };
115 }
116 if flex {
117 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
118 }
119 Ok(out)
120 }
121}
122#[cfg(test)]
123impl ListPartitionReassignmentsRequest {
124 #[must_use]
125 pub fn populated(version: i16) -> Self {
126 let mut m = Self::default();
127 if version >= 0 {
128 m.timeout_ms = 1i32;
129 }
130 if version >= 0 {
131 m.topics = Some(vec![ListPartitionReassignmentsTopics::populated(version)]);
132 }
133 m
134 }
135}
136#[derive(Debug, Clone, PartialEq, Eq, Default)]
137pub struct ListPartitionReassignmentsTopics {
138 pub name: String,
139 pub partition_indexes: Vec<i32>,
140 pub unknown_tagged_fields: UnknownTaggedFields,
141}
142impl Encode for ListPartitionReassignmentsTopics {
143 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
144 let flex = version >= 0;
145 if version >= 0 {
146 if flex {
147 put_compact_string(buf, &self.name);
148 } else {
149 put_string(buf, &self.name);
150 }
151 }
152 if version >= 0 {
153 {
154 crate::primitives::array::put_array_len(buf, (self.partition_indexes).len(), flex);
155 for it in &self.partition_indexes {
156 put_i32(buf, *it);
157 }
158 }
159 }
160 if flex {
161 let tagged = WriteTaggedFields::new();
162 tagged.write(buf, &self.unknown_tagged_fields);
163 }
164 Ok(())
165 }
166 fn encoded_len(&self, version: i16) -> usize {
167 let flex = version >= 0;
168 let mut n: usize = 0;
169 if version >= 0 {
170 n += if flex {
171 compact_string_len(&self.name)
172 } else {
173 string_len(&self.name)
174 };
175 }
176 if version >= 0 {
177 n += {
178 let prefix = crate::primitives::array::array_len_prefix_len(
179 (self.partition_indexes).len(),
180 flex,
181 );
182 let body: usize = (self.partition_indexes).iter().map(|_| 4).sum();
183 prefix + body
184 };
185 }
186 if flex {
187 let known_pairs: Vec<(u32, usize)> = Vec::new();
188 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
189 }
190 n
191 }
192}
193impl Decode<'_> for ListPartitionReassignmentsTopics {
194 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
195 let flex = version >= 0;
196 let mut out = Self::default();
197 if version >= 0 {
198 out.name = if flex {
199 get_compact_string_owned(buf)?
200 } else {
201 get_string_owned(buf)?
202 };
203 }
204 if version >= 0 {
205 out.partition_indexes = {
206 let n = crate::primitives::array::get_array_len(buf, flex)?;
207 let mut v = Vec::with_capacity(n);
208 for _ in 0..n {
209 v.push(get_i32(buf)?);
210 }
211 v
212 };
213 }
214 if flex {
215 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
216 }
217 Ok(out)
218 }
219}
220#[cfg(test)]
221impl ListPartitionReassignmentsTopics {
222 #[must_use]
223 pub fn populated(version: i16) -> Self {
224 let mut m = Self::default();
225 if version >= 0 {
226 m.name = "x".to_string();
227 }
228 if version >= 0 {
229 m.partition_indexes = vec![1i32];
230 }
231 m
232 }
233}
234#[must_use]
237#[allow(unused_comparisons)]
238pub fn default_json(version: i16) -> ::serde_json::Value {
239 let mut obj = ::serde_json::Map::new();
240 obj.insert("timeoutMs".to_string(), ::serde_json::json!(60000));
241 obj.insert("topics".to_string(), ::serde_json::Value::Null);
242 ::serde_json::Value::Object(obj)
243}
244impl crate::ProtocolRequest for ListPartitionReassignmentsRequest {
245 const API_KEY: i16 = API_KEY;
246 const MIN_VERSION: i16 = MIN_VERSION;
247 const MAX_VERSION: i16 = MAX_VERSION;
248 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
249 type Response =
250 super::list_partition_reassignments_response::ListPartitionReassignmentsResponse;
251}