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 {
13    version >= FLEXIBLE_MIN
14}
15
16#[derive(Debug, Clone, PartialEq, Eq, Default)]
17pub struct EndTxnMarker {
18    pub coordinator_epoch: i32,
19    pub unknown_tagged_fields: UnknownTaggedFields,
20}
21impl EndTxnMarker {
22    pub fn to_owned(&self) -> crate::owned::end_txn_marker::EndTxnMarker {
23        crate::owned::end_txn_marker::EndTxnMarker {
24            coordinator_epoch: (self.coordinator_epoch),
25            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
26        }
27    }
28}
29impl Encode for EndTxnMarker {
30    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
31        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
32            return Err(ProtocolError::SchemaMismatch(
33                "EndTxnMarker version out of range",
34            ));
35        }
36        let flex = is_flexible(version);
37        if version >= 0 {
38            put_i32(buf, self.coordinator_epoch);
39        }
40        Ok(())
41    }
42    fn encoded_len(&self, version: i16) -> usize {
43        let flex = is_flexible(version);
44        let mut n: usize = 0;
45        if version >= 0 {
46            n += 4;
47        }
48        n
49    }
50}
51impl<'de> DecodeBorrow<'de> for EndTxnMarker {
52    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
53        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
54            return Err(ProtocolError::SchemaMismatch(
55                "EndTxnMarker version out of range",
56            ));
57        }
58        let flex = is_flexible(version);
59        let mut out = Self::default();
60        if version >= 0 {
61            out.coordinator_epoch = get_i32(buf)?;
62        }
63        Ok(out)
64    }
65}
66#[cfg(test)]
67impl EndTxnMarker {
68    #[must_use]
69    pub fn populated(version: i16) -> Self {
70        let mut m = Self::default();
71        if version >= 0 {
72            m.coordinator_epoch = 1i32;
73        }
74        m
75    }
76}