Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ExpireDelegationTokenResponse.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::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::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
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
14#[inline]
15fn is_flexible(version: i16) -> bool {
16    version >= FLEXIBLE_MIN
17}
18
19#[derive(Debug, Clone, PartialEq, Eq, Default)]
20pub struct ExpireDelegationTokenResponse {
21    pub error_code: i16,
22    pub expiry_timestamp_ms: i64,
23    pub throttle_time_ms: i32,
24    pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl ExpireDelegationTokenResponse {
27    pub fn to_owned(
28        &self,
29    ) -> crate::owned::expire_delegation_token_response::ExpireDelegationTokenResponse {
30        crate::owned::expire_delegation_token_response::ExpireDelegationTokenResponse {
31            error_code: (self.error_code),
32            expiry_timestamp_ms: (self.expiry_timestamp_ms),
33            throttle_time_ms: (self.throttle_time_ms),
34            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
35        }
36    }
37}
38impl Encode for ExpireDelegationTokenResponse {
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_i16(buf, self.error_code);
49        }
50        if version >= 0 {
51            put_i64(buf, self.expiry_timestamp_ms);
52        }
53        if version >= 0 {
54            put_i32(buf, self.throttle_time_ms);
55        }
56        if flex {
57            let tagged = WriteTaggedFields::new();
58            tagged.write(buf, &self.unknown_tagged_fields);
59        }
60        Ok(())
61    }
62    fn encoded_len(&self, version: i16) -> usize {
63        let flex = is_flexible(version);
64        let mut n: usize = 0;
65        if version >= 0 {
66            n += 2;
67        }
68        if version >= 0 {
69            n += 8;
70        }
71        if version >= 0 {
72            n += 4;
73        }
74        if flex {
75            let known_pairs: Vec<(u32, usize)> = Vec::new();
76            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
77        }
78        n
79    }
80}
81impl<'de> DecodeBorrow<'de> for ExpireDelegationTokenResponse {
82    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
83        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
84            return Err(ProtocolError::UnsupportedVersion {
85                api_key: API_KEY,
86                version,
87            });
88        }
89        let flex = is_flexible(version);
90        let mut out = Self::default();
91        if version >= 0 {
92            out.error_code = get_i16(buf)?;
93        }
94        if version >= 0 {
95            out.expiry_timestamp_ms = get_i64(buf)?;
96        }
97        if version >= 0 {
98            out.throttle_time_ms = get_i32(buf)?;
99        }
100        if flex {
101            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
102        }
103        Ok(out)
104    }
105}
106#[cfg(test)]
107impl ExpireDelegationTokenResponse {
108    #[must_use]
109    pub fn populated(version: i16) -> Self {
110        let mut m = Self::default();
111        if version >= 0 {
112            m.error_code = 1i16;
113        }
114        if version >= 0 {
115            m.expiry_timestamp_ms = 1i64;
116        }
117        if version >= 0 {
118            m.throttle_time_ms = 1i32;
119        }
120        m
121    }
122}