crabka_protocol/opt/rustwide/workdir/generated/common/owned/
TopicPartition.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i32, put_i32};
6use crate::primitives::string_bytes::{
7 compact_string_len, get_compact_string_owned, get_string_owned,
8 put_compact_string, put_string, string_len,
9};
10use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
13#[derive(Debug, Clone, PartialEq, Eq, Default)]
14pub struct TopicPartition {
15 pub topic: String,
16 pub partitions: Vec<i32>,
17 pub unknown_tagged_fields: UnknownTaggedFields,
18}
19
20impl Encode for TopicPartition {
21 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
22 let flex = version >= 0;
23 if version >= 0 { if flex { put_compact_string(buf, &self.topic) } else { put_string(buf, &self.topic) } }
24 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { put_i32(buf, *it); } } }
25 if flex {
26 let tagged = WriteTaggedFields::new();
27 tagged.write(buf, &self.unknown_tagged_fields);
28 }
29 Ok(())
30 }
31 fn encoded_len(&self, version: i16) -> usize {
32 let flex = version >= 0;
33 let mut n: usize = 0;
34 if version >= 0 { n += if flex { compact_string_len(&self.topic) } else { string_len(&self.topic) }; }
35 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex); let body: usize = (self.partitions).iter().map(|_| 4).sum(); prefix + body }; }
36 if flex {
37 let known_pairs: Vec<(u32, usize)> = Vec::new();
38 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
39 }
40 n
41 }
42}
43
44impl<'de> Decode<'de> for TopicPartition {
45 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
46 let flex = version >= 0;
47 let mut out = Self::default();
48 if version >= 0 { out.topic = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
49 if version >= 0 { out.partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(get_i32(buf)?); } v }; }
50 if flex {
51 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
52 Ok(false)
53 })?;
54 }
55 Ok(out)
56 }
57}