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