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