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