krabka_protocol/opt/rustwide/workdir/generated/
DeleteShareGroupStateResponse.borrowed.rs1use bytes::BufMut;
3
4use crate::{
5 DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6 primitives::{
7 fixed::{get_i16, get_i32, put_i16, put_i32},
8 string_bytes::{
9 compact_nullable_string_len, nullable_string_len, put_compact_nullable_string,
10 put_nullable_string,
11 },
12 string_bytes_borrowed::{
13 get_compact_nullable_string_borrowed, get_nullable_string_borrowed,
14 },
15 },
16 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const API_KEY: i16 = 86;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 0;
21pub const FLEXIBLE_MIN: i16 = 0;
22#[inline]
23#[must_use]
24pub fn is_flexible(version: i16) -> bool {
25 version >= FLEXIBLE_MIN
26}
27#[derive(Debug, Clone, PartialEq, Eq, Default)]
28pub struct DeleteShareGroupStateResponse<'a> {
29 pub results: Vec<DeleteStateResult<'a>>,
30 pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl DeleteShareGroupStateResponse<'_> {
33 #[must_use]
37 pub fn to_owned(
38 &self,
39 ) -> crate::owned::delete_share_group_state_response::DeleteShareGroupStateResponse {
40 crate::owned::delete_share_group_state_response::DeleteShareGroupStateResponse {
41 results: (self.results)
42 .iter()
43 .map(DeleteStateResult::to_owned)
44 .collect(),
45 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
46 }
47 }
48}
49impl Encode for DeleteShareGroupStateResponse<'_> {
50 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
51 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
52 return Err(ProtocolError::UnsupportedVersion {
53 api_key: API_KEY,
54 version,
55 });
56 }
57 let flex = is_flexible(version);
58 if version >= 0 {
59 {
60 crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
61 for it in &self.results {
62 it.encode(buf, version)?;
63 }
64 };
65 }
66 if flex {
67 let tagged = WriteTaggedFields::new();
68 tagged.write(buf, &self.unknown_tagged_fields);
69 }
70 Ok(())
71 }
72 fn encoded_len(&self, version: i16) -> usize {
73 let flex = is_flexible(version);
74 let mut n: usize = 0;
75 if version >= 0 {
76 n += {
77 let prefix =
78 crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
79 let body: usize = (self.results)
80 .iter()
81 .map(|it| it.encoded_len(version))
82 .sum();
83 prefix + body
84 };
85 }
86 if flex {
87 let known_pairs: Vec<(u32, usize)> = Vec::new();
88 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
89 }
90 n
91 }
92}
93impl<'de> DecodeBorrow<'de> for DeleteShareGroupStateResponse<'de> {
94 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
95 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
96 return Err(ProtocolError::UnsupportedVersion {
97 api_key: API_KEY,
98 version,
99 });
100 }
101 let flex = is_flexible(version);
102 let mut out = Self::default();
103 if version >= 0 {
104 out.results = {
105 let n = crate::primitives::array::get_array_len(buf, flex)?;
106 let mut v = Vec::with_capacity(n);
107 for _ in 0..n {
108 v.push(DeleteStateResult::decode_borrow(buf, version)?);
109 }
110 v
111 };
112 }
113 if flex {
114 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
115 }
116 Ok(out)
117 }
118}
119#[cfg(test)]
120impl DeleteShareGroupStateResponse<'_> {
121 #[must_use]
122 pub fn populated(version: i16) -> Self {
123 let mut m = Self::default();
124 if version >= 0 {
125 m.results = vec![DeleteStateResult::populated(version)];
126 }
127 m
128 }
129}
130#[derive(Debug, Clone, PartialEq, Eq, Default)]
131pub struct DeleteStateResult<'a> {
132 pub topic_id: crate::primitives::uuid::Uuid,
133 pub partitions: Vec<PartitionResult<'a>>,
134 pub unknown_tagged_fields: UnknownTaggedFields,
135}
136impl DeleteStateResult<'_> {
137 #[must_use]
141 pub fn to_owned(&self) -> crate::owned::delete_share_group_state_response::DeleteStateResult {
142 crate::owned::delete_share_group_state_response::DeleteStateResult {
143 topic_id: (self.topic_id),
144 partitions: (self.partitions)
145 .iter()
146 .map(PartitionResult::to_owned)
147 .collect(),
148 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
149 }
150 }
151}
152impl Encode for DeleteStateResult<'_> {
153 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
154 let flex = version >= 0;
155 if version >= 0 {
156 crate::primitives::uuid::put_uuid(buf, self.topic_id);
157 }
158 if version >= 0 {
159 {
160 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
161 for it in &self.partitions {
162 it.encode(buf, version)?;
163 }
164 };
165 }
166 if flex {
167 let tagged = WriteTaggedFields::new();
168 tagged.write(buf, &self.unknown_tagged_fields);
169 }
170 Ok(())
171 }
172 fn encoded_len(&self, version: i16) -> usize {
173 let flex = version >= 0;
174 let mut n: usize = 0;
175 if version >= 0 {
176 n += 16;
177 }
178 if version >= 0 {
179 n += {
180 let prefix =
181 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
182 let body: usize = (self.partitions)
183 .iter()
184 .map(|it| it.encoded_len(version))
185 .sum();
186 prefix + body
187 };
188 }
189 if flex {
190 let known_pairs: Vec<(u32, usize)> = Vec::new();
191 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
192 }
193 n
194 }
195}
196impl<'de> DecodeBorrow<'de> for DeleteStateResult<'de> {
197 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
198 let flex = version >= 0;
199 let mut out = Self::default();
200 if version >= 0 {
201 out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
202 }
203 if version >= 0 {
204 out.partitions = {
205 let n = crate::primitives::array::get_array_len(buf, flex)?;
206 let mut v = Vec::with_capacity(n);
207 for _ in 0..n {
208 v.push(PartitionResult::decode_borrow(buf, version)?);
209 }
210 v
211 };
212 }
213 if flex {
214 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
215 }
216 Ok(out)
217 }
218}
219#[cfg(test)]
220impl DeleteStateResult<'_> {
221 #[must_use]
222 pub fn populated(version: i16) -> Self {
223 let mut m = Self::default();
224 if version >= 0 {
225 m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
226 }
227 if version >= 0 {
228 m.partitions = vec![PartitionResult::populated(version)];
229 }
230 m
231 }
232}
233#[derive(Debug, Clone, PartialEq, Eq, Default)]
234pub struct PartitionResult<'a> {
235 pub partition: i32,
236 pub error_code: i16,
237 pub error_message: Option<&'a str>,
238 pub unknown_tagged_fields: UnknownTaggedFields,
239}
240impl PartitionResult<'_> {
241 #[must_use]
245 pub fn to_owned(&self) -> crate::owned::delete_share_group_state_response::PartitionResult {
246 crate::owned::delete_share_group_state_response::PartitionResult {
247 partition: (self.partition),
248 error_code: (self.error_code),
249 error_message: (self.error_message).map(std::string::ToString::to_string),
250 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
251 }
252 }
253}
254impl Encode for PartitionResult<'_> {
255 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
256 let flex = version >= 0;
257 if version >= 0 {
258 put_i32(buf, self.partition);
259 }
260 if version >= 0 {
261 put_i16(buf, self.error_code);
262 }
263 if version >= 0 {
264 if flex {
265 let () = put_compact_nullable_string(buf, self.error_message);
266 } else {
267 let () = put_nullable_string(buf, self.error_message);
268 }
269 }
270 if flex {
271 let tagged = WriteTaggedFields::new();
272 tagged.write(buf, &self.unknown_tagged_fields);
273 }
274 Ok(())
275 }
276 fn encoded_len(&self, version: i16) -> usize {
277 let flex = version >= 0;
278 let mut n: usize = 0;
279 if version >= 0 {
280 n += 4;
281 }
282 if version >= 0 {
283 n += 2;
284 }
285 if version >= 0 {
286 n += if flex {
287 compact_nullable_string_len(self.error_message)
288 } else {
289 nullable_string_len(self.error_message)
290 };
291 }
292 if flex {
293 let known_pairs: Vec<(u32, usize)> = Vec::new();
294 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
295 }
296 n
297 }
298}
299impl<'de> DecodeBorrow<'de> for PartitionResult<'de> {
300 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
301 let flex = version >= 0;
302 let mut out = Self::default();
303 if version >= 0 {
304 out.partition = get_i32(buf)?;
305 }
306 if version >= 0 {
307 out.error_code = get_i16(buf)?;
308 }
309 if version >= 0 {
310 out.error_message = if flex {
311 get_compact_nullable_string_borrowed(buf)?
312 } else {
313 get_nullable_string_borrowed(buf)?
314 };
315 }
316 if flex {
317 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
318 }
319 Ok(out)
320 }
321}
322#[cfg(test)]
323impl PartitionResult<'_> {
324 #[must_use]
325 pub fn populated(version: i16) -> Self {
326 let mut m = Self::default();
327 if version >= 0 {
328 m.partition = 1i32;
329 }
330 if version >= 0 {
331 m.error_code = 1i16;
332 }
333 if version >= 0 {
334 m.error_message = Some("x");
335 }
336 m
337 }
338}