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