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