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