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