Skip to main content

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

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::{
6    Decode, Encode, ProtocolError, UnknownTaggedFields,
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 Encode for EndTxnMarker {
23    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
24        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
25            return Err(ProtocolError::SchemaMismatch(
26                "EndTxnMarker version out of range",
27            ));
28        }
29        if version >= 0 {
30            put_i32(buf, self.coordinator_epoch);
31        }
32        Ok(())
33    }
34    fn encoded_len(&self, version: i16) -> usize {
35        let mut n: usize = 0;
36        if version >= 0 {
37            n += 4;
38        }
39        n
40    }
41}
42impl Decode<'_> for EndTxnMarker {
43    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
44        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
45            return Err(ProtocolError::SchemaMismatch(
46                "EndTxnMarker version out of range",
47            ));
48        }
49        let mut out = Self::default();
50        if version >= 0 {
51            out.coordinator_epoch = get_i32(buf)?;
52        }
53        Ok(out)
54    }
55}
56#[cfg(test)]
57impl EndTxnMarker {
58    #[must_use]
59    pub fn populated(version: i16) -> Self {
60        let mut m = Self::default();
61        if version >= 0 {
62            m.coordinator_epoch = 1i32;
63        }
64        m
65    }
66}
67/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
68/// Only includes fields valid for the given version.
69#[must_use]
70#[allow(unused_comparisons)]
71pub fn default_json(_version: i16) -> ::serde_json::Value {
72    let mut obj = ::serde_json::Map::new();
73    obj.insert("coordinatorEpoch".to_string(), ::serde_json::json!(0));
74    ::serde_json::Value::Object(obj)
75}