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