Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
AddOffsetsToTxnResponse.borrowed.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2use bytes::BufMut;
3
4use crate::{
5    DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6    primitives::fixed::{get_i16, get_i32, put_i16, put_i32},
7    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
8};
9pub const API_KEY: i16 = 25;
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 4;
12pub const FLEXIBLE_MIN: i16 = 3;
13#[inline]
14#[must_use]
15pub fn is_flexible(version: i16) -> bool {
16    version >= FLEXIBLE_MIN
17}
18#[derive(Debug, Clone, PartialEq, Eq, Default)]
19pub struct AddOffsetsToTxnResponse {
20    pub throttle_time_ms: i32,
21    pub error_code: i16,
22    pub unknown_tagged_fields: UnknownTaggedFields,
23}
24impl AddOffsetsToTxnResponse {
25    /// # Panics
26    ///
27    /// Panics if a records field contains an invalid encoded record batch.
28    #[must_use]
29    pub fn to_owned(&self) -> crate::owned::add_offsets_to_txn_response::AddOffsetsToTxnResponse {
30        crate::owned::add_offsets_to_txn_response::AddOffsetsToTxnResponse {
31            throttle_time_ms: (self.throttle_time_ms),
32            error_code: (self.error_code),
33            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
34        }
35    }
36}
37impl Encode for AddOffsetsToTxnResponse {
38    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
39        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
40            return Err(ProtocolError::UnsupportedVersion {
41                api_key: API_KEY,
42                version,
43            });
44        }
45        let flex = is_flexible(version);
46        if version >= 0 {
47            put_i32(buf, self.throttle_time_ms);
48        }
49        if version >= 0 {
50            put_i16(buf, self.error_code);
51        }
52        if flex {
53            let tagged = WriteTaggedFields::new();
54            tagged.write(buf, &self.unknown_tagged_fields);
55        }
56        Ok(())
57    }
58    fn encoded_len(&self, version: i16) -> usize {
59        let flex = is_flexible(version);
60        let mut n: usize = 0;
61        if version >= 0 {
62            n += 4;
63        }
64        if version >= 0 {
65            n += 2;
66        }
67        if flex {
68            let known_pairs: Vec<(u32, usize)> = Vec::new();
69            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
70        }
71        n
72    }
73}
74impl<'de> DecodeBorrow<'de> for AddOffsetsToTxnResponse {
75    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
76        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
77            return Err(ProtocolError::UnsupportedVersion {
78                api_key: API_KEY,
79                version,
80            });
81        }
82        let flex = is_flexible(version);
83        let mut out = Self::default();
84        if version >= 0 {
85            out.throttle_time_ms = get_i32(buf)?;
86        }
87        if version >= 0 {
88            out.error_code = get_i16(buf)?;
89        }
90        if flex {
91            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
92        }
93        Ok(out)
94    }
95}
96#[cfg(test)]
97impl AddOffsetsToTxnResponse {
98    #[must_use]
99    pub fn populated(version: i16) -> Self {
100        let mut m = Self::default();
101        if version >= 0 {
102            m.throttle_time_ms = 1i32;
103        }
104        if version >= 0 {
105            m.error_code = 1i16;
106        }
107        m
108    }
109}