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