crabka_protocol/opt/rustwide/workdir/generated/
EndTxnMarker.owned.rs1use crate::primitives::fixed::{get_i32, put_i32};
4use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
5use bytes::{Buf, BufMut};
6pub const MIN_VERSION: i16 = 0;
7pub const MAX_VERSION: i16 = 0;
8pub const FLEXIBLE_MIN: i16 = 32767;
9#[inline]
10fn is_flexible(version: i16) -> bool {
11 version >= FLEXIBLE_MIN
12}
13#[derive(Debug, Clone, PartialEq, Eq, Default)]
14pub struct EndTxnMarker {
15 pub coordinator_epoch: i32,
16 pub unknown_tagged_fields: UnknownTaggedFields,
17}
18impl Encode for EndTxnMarker {
19 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
20 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
21 return Err(ProtocolError::SchemaMismatch(
22 "EndTxnMarker version out of range",
23 ));
24 }
25 let flex = is_flexible(version);
26 if version >= 0 {
27 put_i32(buf, self.coordinator_epoch);
28 }
29 Ok(())
30 }
31 fn encoded_len(&self, version: i16) -> usize {
32 let flex = is_flexible(version);
33 let mut n: usize = 0;
34 if version >= 0 {
35 n += 4;
36 }
37 n
38 }
39}
40impl Decode<'_> for EndTxnMarker {
41 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
42 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
43 return Err(ProtocolError::SchemaMismatch(
44 "EndTxnMarker version out of range",
45 ));
46 }
47 let flex = is_flexible(version);
48 let mut out = Self::default();
49 if version >= 0 {
50 out.coordinator_epoch = get_i32(buf)?;
51 }
52 Ok(out)
53 }
54}
55#[cfg(test)]
56impl EndTxnMarker {
57 #[must_use]
58 pub fn populated(version: i16) -> Self {
59 let mut m = Self::default();
60 if version >= 0 {
61 m.coordinator_epoch = 1i32;
62 }
63 m
64 }
65}
66#[must_use]
69#[allow(unused_comparisons)]
70pub fn default_json(version: i16) -> ::serde_json::Value {
71 let mut obj = ::serde_json::Map::new();
72 obj.insert("coordinatorEpoch".to_string(), ::serde_json::json!(0));
73 ::serde_json::Value::Object(obj)
74}