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