Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
EndTxnResponse.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64};
4use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
5use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
6use bytes::{Buf, BufMut};
7pub const API_KEY: i16 = 26;
8pub const MIN_VERSION: i16 = 0;
9pub const MAX_VERSION: i16 = 5;
10pub const FLEXIBLE_MIN: i16 = 3;
11#[inline]
12fn is_flexible(version: i16) -> bool {
13    version >= FLEXIBLE_MIN
14}
15#[derive(Debug, Clone, PartialEq, Eq)]
16pub struct EndTxnResponse {
17    pub throttle_time_ms: i32,
18    pub error_code: i16,
19    pub producer_id: i64,
20    pub producer_epoch: i16,
21    pub unknown_tagged_fields: UnknownTaggedFields,
22}
23impl Default for EndTxnResponse {
24    fn default() -> Self {
25        Self {
26            throttle_time_ms: 0i32,
27            error_code: 0i16,
28            producer_id: -1i64,
29            producer_epoch: -1i16,
30            unknown_tagged_fields: Default::default(),
31        }
32    }
33}
34impl Encode for EndTxnResponse {
35    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
36        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
37            return Err(ProtocolError::UnsupportedVersion {
38                api_key: API_KEY,
39                version,
40            });
41        }
42        let flex = is_flexible(version);
43        if version >= 0 {
44            put_i32(buf, self.throttle_time_ms);
45        }
46        if version >= 0 {
47            put_i16(buf, self.error_code);
48        }
49        if version >= 5 {
50            put_i64(buf, self.producer_id);
51        }
52        if version >= 5 {
53            put_i16(buf, self.producer_epoch);
54        }
55        if flex {
56            let tagged = WriteTaggedFields::new();
57            tagged.write(buf, &self.unknown_tagged_fields);
58        }
59        Ok(())
60    }
61    fn encoded_len(&self, version: i16) -> usize {
62        let flex = is_flexible(version);
63        let mut n: usize = 0;
64        if version >= 0 {
65            n += 4;
66        }
67        if version >= 0 {
68            n += 2;
69        }
70        if version >= 5 {
71            n += 8;
72        }
73        if version >= 5 {
74            n += 2;
75        }
76        if flex {
77            let known_pairs: Vec<(u32, usize)> = Vec::new();
78            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
79        }
80        n
81    }
82}
83impl Decode<'_> for EndTxnResponse {
84    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
85        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
86            return Err(ProtocolError::UnsupportedVersion {
87                api_key: API_KEY,
88                version,
89            });
90        }
91        let flex = is_flexible(version);
92        let mut out = Self::default();
93        if version >= 0 {
94            out.throttle_time_ms = get_i32(buf)?;
95        }
96        if version >= 0 {
97            out.error_code = get_i16(buf)?;
98        }
99        if version >= 5 {
100            out.producer_id = get_i64(buf)?;
101        }
102        if version >= 5 {
103            out.producer_epoch = get_i16(buf)?;
104        }
105        if flex {
106            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
107        }
108        Ok(out)
109    }
110}
111#[cfg(test)]
112impl EndTxnResponse {
113    #[must_use]
114    pub fn populated(version: i16) -> Self {
115        let mut m = Self::default();
116        if version >= 0 {
117            m.throttle_time_ms = 1i32;
118        }
119        if version >= 0 {
120            m.error_code = 1i16;
121        }
122        if version >= 5 {
123            m.producer_id = 1i64;
124        }
125        if version >= 5 {
126            m.producer_epoch = 1i16;
127        }
128        m
129    }
130}
131/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
132/// Only includes fields valid for the given version.
133#[must_use]
134#[allow(unused_comparisons)]
135pub fn default_json(version: i16) -> ::serde_json::Value {
136    let mut obj = ::serde_json::Map::new();
137    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
138    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
139    if version >= 5 {
140        obj.insert("producerId".to_string(), ::serde_json::json!(-1));
141    }
142    if version >= 5 {
143        obj.insert("producerEpoch".to_string(), ::serde_json::json!(-1));
144    }
145    ::serde_json::Value::Object(obj)
146}