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