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