Skip to main content

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

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use bytes::BufMut;
3
4use crate::{
5    DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6    owned::end_txn_marker,
7    primitives::fixed::{get_i32, put_i32},
8};
9pub const MIN_VERSION: i16 = 0;
10pub const MAX_VERSION: i16 = 0;
11pub const FLEXIBLE_MIN: i16 = 32767;
12#[inline]
13#[must_use]
14pub fn is_flexible(version: i16) -> bool {
15    version == FLEXIBLE_MIN
16}
17#[derive(Debug, Clone, PartialEq, Eq, Default)]
18pub struct EndTxnMarker {
19    pub coordinator_epoch: i32,
20    pub unknown_tagged_fields: UnknownTaggedFields,
21}
22impl EndTxnMarker {
23    #[must_use]
24    pub fn to_owned(&self) -> end_txn_marker::EndTxnMarker {
25        end_txn_marker::EndTxnMarker {
26            coordinator_epoch: (self.coordinator_epoch),
27            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
28        }
29    }
30}
31impl Encode for EndTxnMarker {
32    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
33        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
34            return Err(ProtocolError::SchemaMismatch(
35                "EndTxnMarker version out of range",
36            ));
37        }
38        if version >= 0 {
39            put_i32(buf, self.coordinator_epoch);
40        }
41        Ok(())
42    }
43    fn encoded_len(&self, version: i16) -> usize {
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 mut out = Self::default();
59        if version >= 0 {
60            out.coordinator_epoch = get_i32(buf)?;
61        }
62        Ok(out)
63    }
64}
65#[cfg(test)]
66impl EndTxnMarker {
67    #[must_use]
68    pub fn populated(version: i16) -> Self {
69        let mut m = Self::default();
70        if version >= 0 {
71            m.coordinator_epoch = 1i32;
72        }
73        m
74    }
75}