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