Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
EndTxnMarker.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i32, put_i32};
6use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
7pub const MIN_VERSION: i16 = 0;
8pub const MAX_VERSION: i16 = 0;
9pub const FLEXIBLE_MIN: i16 = 32767;
10
11#[inline]
12fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
13
14#[derive(Debug, Clone, PartialEq, Eq)]
15pub struct EndTxnMarker {
16    pub coordinator_epoch: i32,
17    pub unknown_tagged_fields: UnknownTaggedFields,
18}
19
20impl Default for EndTxnMarker {
21    fn default() -> Self {
22        Self {
23            coordinator_epoch: 0i32,
24            unknown_tagged_fields: Default::default(),
25        }
26    }
27}
28
29impl EndTxnMarker {
30    pub fn to_owned(&self) -> crate::owned::end_txn_marker::EndTxnMarker {
31        crate::owned::end_txn_marker::EndTxnMarker {
32            coordinator_epoch: (self.coordinator_epoch),
33            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
34        }
35    }
36}
37
38impl Encode for EndTxnMarker {
39    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
40        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
41            return Err(ProtocolError::SchemaMismatch("EndTxnMarker version out of range"));
42        }
43        let flex = is_flexible(version);
44        if version >= 0 { put_i32(buf, self.coordinator_epoch) }
45        Ok(())
46    }
47    fn encoded_len(&self, version: i16) -> usize {
48        let flex = is_flexible(version);
49        let mut n: usize = 0;
50        if version >= 0 { n += 4; }
51        n
52    }
53}
54
55impl<'de> DecodeBorrow<'de> for EndTxnMarker {
56    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
57        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
58            return Err(ProtocolError::SchemaMismatch("EndTxnMarker version out of range"));
59        }
60        let flex = is_flexible(version);
61        let mut out = Self::default();
62        if version >= 0 { out.coordinator_epoch = get_i32(buf)?; }
63        Ok(out)
64    }
65}