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