crabka_protocol/opt/rustwide/workdir/generated/common/owned/
AddPartitionsToTxnPartitionResult.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, put_i16, 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 AddPartitionsToTxnPartitionResult {
11 pub partition_index: i32,
12 pub partition_error_code: i16,
13 pub unknown_tagged_fields: UnknownTaggedFields,
14}
15
16impl Encode for AddPartitionsToTxnPartitionResult {
17 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
18 let flex = version >= 3;
19 if version >= 0 { put_i32(buf, self.partition_index) }
20 if version >= 0 { put_i16(buf, self.partition_error_code) }
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 >= 3;
29 let mut n: usize = 0;
30 if version >= 0 { n += 4; }
31 if version >= 0 { n += 2; }
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 AddPartitionsToTxnPartitionResult {
41 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
42 let flex = version >= 3;
43 let mut out = Self::default();
44 if version >= 0 { out.partition_index = get_i32(buf)?; }
45 if version >= 0 { out.partition_error_code = get_i16(buf)?; }
46 if flex {
47 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
48 Ok(false)
49 })?;
50 }
51 Ok(out)
52 }
53}