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