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 bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64};
6use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
7use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
8
9pub const API_KEY: i16 = 26;
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 5;
12pub const FLEXIBLE_MIN: i16 = 3;
13
14#[inline]
15fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
16
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct EndTxnResponse {
19    pub throttle_time_ms: i32,
20    pub error_code: i16,
21    pub producer_id: i64,
22    pub producer_epoch: i16,
23    pub unknown_tagged_fields: UnknownTaggedFields,
24}
25
26impl Default for EndTxnResponse {
27    fn default() -> Self {
28        Self {
29            throttle_time_ms: 0i32,
30            error_code: 0i16,
31            producer_id: -1i64,
32            producer_epoch: -1i16,
33            unknown_tagged_fields: Default::default(),
34        }
35    }
36}
37
38impl Encode for EndTxnResponse {
39    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
40        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
41            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
42        }
43        let flex = is_flexible(version);
44        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
45        if version >= 0 { put_i16(buf, self.error_code) }
46        if version >= 5 { put_i64(buf, self.producer_id) }
47        if version >= 5 { put_i16(buf, self.producer_epoch) }
48        if flex {
49            let tagged = WriteTaggedFields::new();
50            tagged.write(buf, &self.unknown_tagged_fields);
51        }
52        Ok(())
53    }
54    fn encoded_len(&self, version: i16) -> usize {
55        let flex = is_flexible(version);
56        let mut n: usize = 0;
57        if version >= 0 { n += 4; }
58        if version >= 0 { n += 2; }
59        if version >= 5 { n += 8; }
60        if version >= 5 { n += 2; }
61        if flex {
62            let known_pairs: Vec<(u32, usize)> = Vec::new();
63            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
64        }
65        n
66    }
67}
68
69impl<'de> Decode<'de> for EndTxnResponse {
70    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
71        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
72            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
73        }
74        let flex = is_flexible(version);
75        let mut out = Self::default();
76        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
77        if version >= 0 { out.error_code = get_i16(buf)?; }
78        if version >= 5 { out.producer_id = get_i64(buf)?; }
79        if version >= 5 { out.producer_epoch = get_i16(buf)?; }
80        if flex {
81            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
82                Ok(false)
83            })?;
84        }
85        Ok(out)
86    }
87}
88
89/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
90/// Only includes fields valid for the given version.
91#[must_use]
92#[allow(unused_comparisons)]
93pub fn default_json(version: i16) -> ::serde_json::Value {
94    let mut obj = ::serde_json::Map::new();
95    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
96    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
97    if version >= 5 {
98        obj.insert("producerId".to_string(), ::serde_json::json!(-1));
99    }
100    if version >= 5 {
101        obj.insert("producerEpoch".to_string(), ::serde_json::json!(-1));
102    }
103    ::serde_json::Value::Object(obj)
104}