crabka_protocol/opt/rustwide/workdir/generated/common/owned/
TopicInfo.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, put_i16, 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 TopicInfo {
15 pub name: String,
16 pub partitions: i32,
17 pub replication_factor: i16,
18 pub topic_configs: Vec<super::key_value::KeyValue>,
19 pub unknown_tagged_fields: UnknownTaggedFields,
20}
21
22impl Encode for TopicInfo {
23 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
24 let flex = version >= 0;
25 if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
26 if version >= 0 { put_i32(buf, self.partitions) }
27 if version >= 0 { put_i16(buf, self.replication_factor) }
28 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topic_configs).len(), flex); for it in &self.topic_configs { it.encode(buf, version)?; } } }
29 if flex {
30 let tagged = WriteTaggedFields::new();
31 tagged.write(buf, &self.unknown_tagged_fields);
32 }
33 Ok(())
34 }
35 fn encoded_len(&self, version: i16) -> usize {
36 let flex = version >= 0;
37 let mut n: usize = 0;
38 if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
39 if version >= 0 { n += 4; }
40 if version >= 0 { n += 2; }
41 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topic_configs).len(), flex); let body: usize = (self.topic_configs).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
42 if flex {
43 let known_pairs: Vec<(u32, usize)> = Vec::new();
44 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
45 }
46 n
47 }
48}
49
50impl<'de> Decode<'de> for TopicInfo {
51 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
52 let flex = version >= 0;
53 let mut out = Self::default();
54 if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
55 if version >= 0 { out.partitions = get_i32(buf)?; }
56 if version >= 0 { out.replication_factor = get_i16(buf)?; }
57 if version >= 0 { out.topic_configs = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::key_value::KeyValue::decode(buf, version)?); } v }; }
58 if flex {
59 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
60 Ok(false)
61 })?;
62 }
63 Ok(out)
64 }
65}