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    primitives::fixed::{get_i32, put_i32},
7};
8pub const MIN_VERSION: i16 = 0;
9pub const MAX_VERSION: i16 = 0;
10pub const FLEXIBLE_MIN: i16 = 32767;
11#[inline]
12#[must_use]
13pub fn is_flexible(version: i16) -> bool {
14    version == FLEXIBLE_MIN
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    /// # Panics
23    ///
24    /// Panics if a records field contains an invalid encoded record batch.
25    #[must_use]
26    pub fn to_owned(&self) -> crate::owned::end_txn_marker::EndTxnMarker {
27        crate::owned::end_txn_marker::EndTxnMarker {
28            coordinator_epoch: (self.coordinator_epoch),
29            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
30        }
31    }
32}
33impl Encode for EndTxnMarker {
34    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
35        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
36            return Err(ProtocolError::SchemaMismatch(
37                "EndTxnMarker version out of range",
38            ));
39        }
40        if version >= 0 {
41            put_i32(buf, self.coordinator_epoch);
42        }
43        Ok(())
44    }
45    fn encoded_len(&self, version: i16) -> usize {
46        let mut n: usize = 0;
47        if version >= 0 {
48            n += 4;
49        }
50        n
51    }
52}
53impl<'de> DecodeBorrow<'de> for EndTxnMarker {
54    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
55        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
56            return Err(ProtocolError::SchemaMismatch(
57                "EndTxnMarker version out of range",
58            ));
59        }
60        let mut out = Self::default();
61        if version >= 0 {
62            out.coordinator_epoch = get_i32(buf)?;
63        }
64        Ok(out)
65    }
66}
67#[cfg(test)]
68impl EndTxnMarker {
69    #[must_use]
70    pub fn populated(version: i16) -> Self {
71        let mut m = Self::default();
72        if version >= 0 {
73            m.coordinator_epoch = 1i32;
74        }
75        m
76    }
77}