Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
ExpireDelegationTokenResponse.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, get_i64, put_i16, put_i32, put_i64},
7    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
8};
9pub const API_KEY: i16 = 40;
10pub const MIN_VERSION: i16 = 1;
11pub const MAX_VERSION: i16 = 2;
12pub const FLEXIBLE_MIN: i16 = 2;
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 ExpireDelegationTokenResponse {
20    pub error_code: i16,
21    pub expiry_timestamp_ms: i64,
22    pub throttle_time_ms: i32,
23    pub unknown_tagged_fields: UnknownTaggedFields,
24}
25impl ExpireDelegationTokenResponse {
26    /// # Panics
27    ///
28    /// Panics if a records field contains an invalid encoded record batch.
29    #[must_use]
30    pub fn to_owned(
31        &self,
32    ) -> crate::owned::expire_delegation_token_response::ExpireDelegationTokenResponse {
33        crate::owned::expire_delegation_token_response::ExpireDelegationTokenResponse {
34            error_code: (self.error_code),
35            expiry_timestamp_ms: (self.expiry_timestamp_ms),
36            throttle_time_ms: (self.throttle_time_ms),
37            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
38        }
39    }
40}
41impl Encode for ExpireDelegationTokenResponse {
42    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
43        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
44            return Err(ProtocolError::UnsupportedVersion {
45                api_key: API_KEY,
46                version,
47            });
48        }
49        let flex = is_flexible(version);
50        if version >= 0 {
51            put_i16(buf, self.error_code);
52        }
53        if version >= 0 {
54            put_i64(buf, self.expiry_timestamp_ms);
55        }
56        if version >= 0 {
57            put_i32(buf, self.throttle_time_ms);
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 += 2;
70        }
71        if version >= 0 {
72            n += 8;
73        }
74        if version >= 0 {
75            n += 4;
76        }
77        if flex {
78            let known_pairs: Vec<(u32, usize)> = Vec::new();
79            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
80        }
81        n
82    }
83}
84impl<'de> DecodeBorrow<'de> for ExpireDelegationTokenResponse {
85    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
86        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
87            return Err(ProtocolError::UnsupportedVersion {
88                api_key: API_KEY,
89                version,
90            });
91        }
92        let flex = is_flexible(version);
93        let mut out = Self::default();
94        if version >= 0 {
95            out.error_code = get_i16(buf)?;
96        }
97        if version >= 0 {
98            out.expiry_timestamp_ms = get_i64(buf)?;
99        }
100        if version >= 0 {
101            out.throttle_time_ms = get_i32(buf)?;
102        }
103        if flex {
104            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
105        }
106        Ok(out)
107    }
108}
109#[cfg(test)]
110impl ExpireDelegationTokenResponse {
111    #[must_use]
112    pub fn populated(version: i16) -> Self {
113        let mut m = Self::default();
114        if version >= 0 {
115            m.error_code = 1i16;
116        }
117        if version >= 0 {
118            m.expiry_timestamp_ms = 1i64;
119        }
120        if version >= 0 {
121            m.throttle_time_ms = 1i32;
122        }
123        m
124    }
125}