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