Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AddPartitionsToTxnResponse.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, put_i16, put_i32};
6use crate::primitives::string_bytes::{
7    compact_string_len, get_compact_string_owned, get_string_owned,
8    put_compact_string, put_string, string_len,
9};
10use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 24;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 5;
16pub const FLEXIBLE_MIN: i16 = 3;
17
18#[inline]
19fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
20
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct AddPartitionsToTxnResponse {
23    pub throttle_time_ms: i32,
24    pub error_code: i16,
25    pub results_by_transaction: Vec<AddPartitionsToTxnResult>,
26    pub results_by_topic_v3_and_below: Vec<super::common::add_partitions_to_txn_topic_result::AddPartitionsToTxnTopicResult>,
27    pub unknown_tagged_fields: UnknownTaggedFields,
28}
29
30impl Encode for AddPartitionsToTxnResponse {
31    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
32        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
33            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
34        }
35        let flex = is_flexible(version);
36        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
37        if version >= 4 { put_i16(buf, self.error_code) }
38        if version >= 4 { { crate::primitives::array::put_array_len(buf, (self.results_by_transaction).len(), flex); for it in &self.results_by_transaction { it.encode(buf, version)?; } } }
39        if version >= 0 && version <= 3 { { crate::primitives::array::put_array_len(buf, (self.results_by_topic_v3_and_below).len(), flex); for it in &self.results_by_topic_v3_and_below { it.encode(buf, version)?; } } }
40        if flex {
41            let tagged = WriteTaggedFields::new();
42            tagged.write(buf, &self.unknown_tagged_fields);
43        }
44        Ok(())
45    }
46    fn encoded_len(&self, version: i16) -> usize {
47        let flex = is_flexible(version);
48        let mut n: usize = 0;
49        if version >= 0 { n += 4; }
50        if version >= 4 { n += 2; }
51        if version >= 4 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.results_by_transaction).len(), flex); let body: usize = (self.results_by_transaction).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
52        if version >= 0 && version <= 3 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.results_by_topic_v3_and_below).len(), flex); let body: usize = (self.results_by_topic_v3_and_below).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
53        if flex {
54            let known_pairs: Vec<(u32, usize)> = Vec::new();
55            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
56        }
57        n
58    }
59}
60
61impl<'de> Decode<'de> for AddPartitionsToTxnResponse {
62    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
63        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
64            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
65        }
66        let flex = is_flexible(version);
67        let mut out = Self::default();
68        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
69        if version >= 4 { out.error_code = get_i16(buf)?; }
70        if version >= 4 { out.results_by_transaction = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(AddPartitionsToTxnResult::decode(buf, version)?); } v }; }
71        if version >= 0 && version <= 3 { out.results_by_topic_v3_and_below = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::add_partitions_to_txn_topic_result::AddPartitionsToTxnTopicResult::decode(buf, version)?); } v }; }
72        if flex {
73            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
74                Ok(false)
75            })?;
76        }
77        Ok(out)
78    }
79}
80
81#[derive(Debug, Clone, PartialEq, Eq, Default)]
82pub struct AddPartitionsToTxnResult {
83    pub transactional_id: String,
84    pub topic_results: Vec<super::common::add_partitions_to_txn_topic_result::AddPartitionsToTxnTopicResult>,
85    pub unknown_tagged_fields: UnknownTaggedFields,
86}
87
88impl Encode for AddPartitionsToTxnResult {
89    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
90        let flex = version >= 3;
91        if version >= 4 { if flex { put_compact_string(buf, &self.transactional_id) } else { put_string(buf, &self.transactional_id) } }
92        if version >= 4 { { crate::primitives::array::put_array_len(buf, (self.topic_results).len(), flex); for it in &self.topic_results { it.encode(buf, version)?; } } }
93        if flex {
94            let tagged = WriteTaggedFields::new();
95            tagged.write(buf, &self.unknown_tagged_fields);
96        }
97        Ok(())
98    }
99    fn encoded_len(&self, version: i16) -> usize {
100        let flex = version >= 3;
101        let mut n: usize = 0;
102        if version >= 4 { n += if flex { compact_string_len(&self.transactional_id) } else { string_len(&self.transactional_id) }; }
103        if version >= 4 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.topic_results).len(), flex); let body: usize = (self.topic_results).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
104        if flex {
105            let known_pairs: Vec<(u32, usize)> = Vec::new();
106            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
107        }
108        n
109    }
110}
111
112impl<'de> Decode<'de> for AddPartitionsToTxnResult {
113    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
114        let flex = version >= 3;
115        let mut out = Self::default();
116        if version >= 4 { out.transactional_id = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
117        if version >= 4 { out.topic_results = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(super::common::add_partitions_to_txn_topic_result::AddPartitionsToTxnTopicResult::decode(buf, version)?); } v }; }
118        if flex {
119            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
120                Ok(false)
121            })?;
122        }
123        Ok(out)
124    }
125}
126
127/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
128/// Only includes fields valid for the given version.
129#[must_use]
130#[allow(unused_comparisons)]
131pub fn default_json(version: i16) -> ::serde_json::Value {
132    let mut obj = ::serde_json::Map::new();
133    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
134    if version >= 4 {
135        obj.insert("errorCode".to_string(), ::serde_json::json!(0));
136    }
137    if version >= 4 {
138        obj.insert("resultsByTransaction".to_string(), ::serde_json::Value::Array(vec![]));
139    }
140    if version <= 3 {
141        obj.insert("resultsByTopicV3AndBelow".to_string(), ::serde_json::Value::Array(vec![]));
142    }
143    ::serde_json::Value::Object(obj)
144}