krabka_protocol/opt/rustwide/workdir/generated/
WriteShareGroupStateRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 array::{array_len_prefix_len, get_array_len, put_array_len},
9 fixed::{get_i8, get_i16, get_i32, get_i64, put_i8, put_i16, put_i32, put_i64},
10 string_bytes::{
11 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
12 put_string, string_len,
13 },
14 uuid::{Uuid, get_uuid, put_uuid},
15 },
16 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const API_KEY: i16 = 85;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 1;
21pub const LATEST_STABLE_VERSION: i16 = 1;
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, Default)]
29pub struct WriteShareGroupStateRequest {
30 pub group_id: String,
31 pub topics: Vec<WriteStateData>,
32 pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Encode for WriteShareGroupStateRequest {
35 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
36 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
37 return Err(ProtocolError::UnsupportedVersion {
38 api_key: API_KEY,
39 version,
40 });
41 }
42 let flex = is_flexible(version);
43 if version >= 0 {
44 if flex {
45 put_compact_string(buf, &self.group_id)?;
46 } else {
47 put_string(buf, &self.group_id)?;
48 }
49 }
50 if version >= 0 {
51 {
52 put_array_len(buf, (self.topics).len(), flex)?;
53 for it in &self.topics {
54 it.encode(buf, version)?;
55 }
56 }
57 }
58 if flex {
59 let tagged = WriteTaggedFields::new();
60 tagged.write(buf, &self.unknown_tagged_fields)?;
61 }
62 Ok(())
63 }
64 fn encoded_len(&self, version: i16) -> usize {
65 let flex = is_flexible(version);
66 let mut n: usize = 0;
67 if version >= 0 {
68 n += if flex {
69 compact_string_len(&self.group_id)
70 } else {
71 string_len(&self.group_id)
72 };
73 }
74 if version >= 0 {
75 n += {
76 let prefix = array_len_prefix_len((self.topics).len(), flex);
77 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
78 prefix + body
79 };
80 }
81 if flex {
82 let known_pairs: Vec<(u32, usize)> = Vec::new();
83 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
84 }
85 n
86 }
87}
88impl Decode<'_> for WriteShareGroupStateRequest {
89 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
90 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
91 return Err(ProtocolError::UnsupportedVersion {
92 api_key: API_KEY,
93 version,
94 });
95 }
96 let flex = is_flexible(version);
97 let mut out = Self::default();
98 if version >= 0 {
99 out.group_id = if flex {
100 get_compact_string_owned(buf)?
101 } else {
102 get_string_owned(buf)?
103 };
104 }
105 if version >= 0 {
106 out.topics = {
107 let n = get_array_len(buf, flex)?;
108 let mut v = Vec::with_capacity(n);
109 for _ in 0..n {
110 v.push(WriteStateData::decode(buf, version)?);
111 }
112 v
113 };
114 }
115 if flex {
116 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
117 }
118 Ok(out)
119 }
120}
121#[cfg(test)]
122impl WriteShareGroupStateRequest {
123 #[must_use]
124 pub fn populated(version: i16) -> Self {
125 let mut m = Self::default();
126 if version >= 0 {
127 m.group_id = "x".to_owned();
128 }
129 if version >= 0 {
130 m.topics = vec![WriteStateData::populated(version)];
131 }
132 m
133 }
134}
135#[derive(Debug, Clone, PartialEq, Eq, Default)]
136pub struct WriteStateData {
137 pub topic_id: Uuid,
138 pub partitions: Vec<PartitionData>,
139 pub unknown_tagged_fields: UnknownTaggedFields,
140}
141impl Encode for WriteStateData {
142 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
143 let flex = version >= 0;
144 if version >= 0 {
145 put_uuid(buf, self.topic_id);
146 }
147 if version >= 0 {
148 {
149 put_array_len(buf, (self.partitions).len(), flex)?;
150 for it in &self.partitions {
151 it.encode(buf, version)?;
152 }
153 }
154 }
155 if flex {
156 let tagged = WriteTaggedFields::new();
157 tagged.write(buf, &self.unknown_tagged_fields)?;
158 }
159 Ok(())
160 }
161 fn encoded_len(&self, version: i16) -> usize {
162 let flex = version >= 0;
163 let mut n: usize = 0;
164 if version >= 0 {
165 n += 16;
166 }
167 if version >= 0 {
168 n += {
169 let prefix = array_len_prefix_len((self.partitions).len(), flex);
170 let body: usize = (self.partitions)
171 .iter()
172 .map(|it| it.encoded_len(version))
173 .sum();
174 prefix + body
175 };
176 }
177 if flex {
178 let known_pairs: Vec<(u32, usize)> = Vec::new();
179 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
180 }
181 n
182 }
183}
184impl Decode<'_> for WriteStateData {
185 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
186 let flex = version >= 0;
187 let mut out = Self::default();
188 if version >= 0 {
189 out.topic_id = get_uuid(buf)?;
190 }
191 if version >= 0 {
192 out.partitions = {
193 let n = get_array_len(buf, flex)?;
194 let mut v = Vec::with_capacity(n);
195 for _ in 0..n {
196 v.push(PartitionData::decode(buf, version)?);
197 }
198 v
199 };
200 }
201 if flex {
202 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
203 }
204 Ok(out)
205 }
206}
207#[cfg(test)]
208impl WriteStateData {
209 #[must_use]
210 pub fn populated(version: i16) -> Self {
211 let mut m = Self::default();
212 if version >= 0 {
213 m.topic_id = Uuid([1u8; 16]);
214 }
215 if version >= 0 {
216 m.partitions = vec![PartitionData::populated(version)];
217 }
218 m
219 }
220}
221#[derive(Debug, Clone, PartialEq, Eq)]
222pub struct PartitionData {
223 pub partition: i32,
224 pub state_epoch: i32,
225 pub leader_epoch: i32,
226 pub start_offset: i64,
227 pub delivery_complete_count: i32,
228 pub state_batches: Vec<StateBatch>,
229 pub unknown_tagged_fields: UnknownTaggedFields,
230}
231impl Default for PartitionData {
232 fn default() -> Self {
233 Self {
234 partition: 0i32,
235 state_epoch: 0i32,
236 leader_epoch: 0i32,
237 start_offset: 0i64,
238 delivery_complete_count: -1i32,
239 state_batches: Vec::new(),
240 unknown_tagged_fields: UnknownTaggedFields::default(),
241 }
242 }
243}
244impl Encode for PartitionData {
245 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
246 let flex = version >= 0;
247 if version >= 0 {
248 put_i32(buf, self.partition);
249 }
250 if version >= 0 {
251 put_i32(buf, self.state_epoch);
252 }
253 if version >= 0 {
254 put_i32(buf, self.leader_epoch);
255 }
256 if version >= 0 {
257 put_i64(buf, self.start_offset);
258 }
259 if version >= 1 {
260 put_i32(buf, self.delivery_complete_count);
261 }
262 if version >= 0 {
263 {
264 put_array_len(buf, (self.state_batches).len(), flex)?;
265 for it in &self.state_batches {
266 it.encode(buf, version)?;
267 }
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 += 4;
284 }
285 if version >= 0 {
286 n += 4;
287 }
288 if version >= 0 {
289 n += 8;
290 }
291 if version >= 1 {
292 n += 4;
293 }
294 if version >= 0 {
295 n += {
296 let prefix = array_len_prefix_len((self.state_batches).len(), flex);
297 let body: usize = (self.state_batches)
298 .iter()
299 .map(|it| it.encoded_len(version))
300 .sum();
301 prefix + body
302 };
303 }
304 if flex {
305 let known_pairs: Vec<(u32, usize)> = Vec::new();
306 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
307 }
308 n
309 }
310}
311impl Decode<'_> for PartitionData {
312 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
313 let flex = version >= 0;
314 let mut out = Self::default();
315 if version >= 0 {
316 out.partition = get_i32(buf)?;
317 }
318 if version >= 0 {
319 out.state_epoch = get_i32(buf)?;
320 }
321 if version >= 0 {
322 out.leader_epoch = get_i32(buf)?;
323 }
324 if version >= 0 {
325 out.start_offset = get_i64(buf)?;
326 }
327 if version >= 1 {
328 out.delivery_complete_count = get_i32(buf)?;
329 }
330 if version >= 0 {
331 out.state_batches = {
332 let n = get_array_len(buf, flex)?;
333 let mut v = Vec::with_capacity(n);
334 for _ in 0..n {
335 v.push(StateBatch::decode(buf, version)?);
336 }
337 v
338 };
339 }
340 if flex {
341 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
342 }
343 Ok(out)
344 }
345}
346#[cfg(test)]
347impl PartitionData {
348 #[must_use]
349 pub fn populated(version: i16) -> Self {
350 let mut m = Self::default();
351 if version >= 0 {
352 m.partition = 1i32;
353 }
354 if version >= 0 {
355 m.state_epoch = 1i32;
356 }
357 if version >= 0 {
358 m.leader_epoch = 1i32;
359 }
360 if version >= 0 {
361 m.start_offset = 1i64;
362 }
363 if version >= 1 {
364 m.delivery_complete_count = 1i32;
365 }
366 if version >= 0 {
367 m.state_batches = vec![StateBatch::populated(version)];
368 }
369 m
370 }
371}
372#[derive(Debug, Clone, PartialEq, Eq, Default)]
373pub struct StateBatch {
374 pub first_offset: i64,
375 pub last_offset: i64,
376 pub delivery_state: i8,
377 pub delivery_count: i16,
378 pub unknown_tagged_fields: UnknownTaggedFields,
379}
380impl Encode for StateBatch {
381 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
382 let flex = version >= 0;
383 if version >= 0 {
384 put_i64(buf, self.first_offset);
385 }
386 if version >= 0 {
387 put_i64(buf, self.last_offset);
388 }
389 if version >= 0 {
390 put_i8(buf, self.delivery_state);
391 }
392 if version >= 0 {
393 put_i16(buf, self.delivery_count);
394 }
395 if flex {
396 let tagged = WriteTaggedFields::new();
397 tagged.write(buf, &self.unknown_tagged_fields)?;
398 }
399 Ok(())
400 }
401 fn encoded_len(&self, version: i16) -> usize {
402 let flex = version >= 0;
403 let mut n: usize = 0;
404 if version >= 0 {
405 n += 8;
406 }
407 if version >= 0 {
408 n += 8;
409 }
410 if version >= 0 {
411 n += 1;
412 }
413 if version >= 0 {
414 n += 2;
415 }
416 if flex {
417 let known_pairs: Vec<(u32, usize)> = Vec::new();
418 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
419 }
420 n
421 }
422}
423impl Decode<'_> for StateBatch {
424 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
425 let flex = version >= 0;
426 let mut out = Self::default();
427 if version >= 0 {
428 out.first_offset = get_i64(buf)?;
429 }
430 if version >= 0 {
431 out.last_offset = get_i64(buf)?;
432 }
433 if version >= 0 {
434 out.delivery_state = get_i8(buf)?;
435 }
436 if version >= 0 {
437 out.delivery_count = get_i16(buf)?;
438 }
439 if flex {
440 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
441 }
442 Ok(out)
443 }
444}
445#[cfg(test)]
446impl StateBatch {
447 #[must_use]
448 pub fn populated(version: i16) -> Self {
449 let mut m = Self::default();
450 if version >= 0 {
451 m.first_offset = 1i64;
452 }
453 if version >= 0 {
454 m.last_offset = 1i64;
455 }
456 if version >= 0 {
457 m.delivery_state = 1i8;
458 }
459 if version >= 0 {
460 m.delivery_count = 1i16;
461 }
462 m
463 }
464}
465#[must_use]
468#[allow(unused_comparisons)]
469pub fn default_json(_version: i16) -> ::serde_json::Value {
470 let mut obj = ::serde_json::Map::new();
471 obj.insert(
472 "groupId".to_owned(),
473 ::serde_json::Value::String(String::new()),
474 );
475 obj.insert("topics".to_owned(), ::serde_json::Value::Array(vec![]));
476 ::serde_json::Value::Object(obj)
477}
478impl crate::ProtocolRequest for WriteShareGroupStateRequest {
479 const API_KEY: i16 = API_KEY;
480 const MIN_VERSION: i16 = MIN_VERSION;
481 const MAX_VERSION: i16 = MAX_VERSION;
482 const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
483 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
484 type Response = super::write_share_group_state_response::WriteShareGroupStateResponse;
485}