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    owned::expire_delegation_token_response,
7    primitives::fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64},
8    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
9};
10pub const API_KEY: i16 = 40;
11pub const MIN_VERSION: i16 = 1;
12pub const MAX_VERSION: i16 = 2;
13pub const FLEXIBLE_MIN: i16 = 2;
14#[inline]
15#[must_use]
16pub fn is_flexible(version: i16) -> bool {
17    version >= FLEXIBLE_MIN
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    #[must_use]
28    pub fn to_owned(&self) -> expire_delegation_token_response::ExpireDelegationTokenResponse {
29        expire_delegation_token_response::ExpireDelegationTokenResponse {
30            error_code: (self.error_code),
31            expiry_timestamp_ms: (self.expiry_timestamp_ms),
32            throttle_time_ms: (self.throttle_time_ms),
33            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
34        }
35    }
36}
37impl Encode for ExpireDelegationTokenResponse {
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_i16(buf, self.error_code);
48        }
49        if version >= 0 {
50            put_i64(buf, self.expiry_timestamp_ms);
51        }
52        if version >= 0 {
53            put_i32(buf, self.throttle_time_ms);
54        }
55        if flex {
56            let tagged = WriteTaggedFields::new();
57            tagged.write(buf, &self.unknown_tagged_fields)?;
58        }
59        Ok(())
60    }
61    fn encoded_len(&self, version: i16) -> usize {
62        let flex = is_flexible(version);
63        let mut n: usize = 0;
64        if version >= 0 {
65            n += 2;
66        }
67        if version >= 0 {
68            n += 8;
69        }
70        if version >= 0 {
71            n += 4;
72        }
73        if flex {
74            let known_pairs: Vec<(u32, usize)> = Vec::new();
75            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
76        }
77        n
78    }
79}
80impl<'de> DecodeBorrow<'de> for ExpireDelegationTokenResponse {
81    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
82        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
83            return Err(ProtocolError::UnsupportedVersion {
84                api_key: API_KEY,
85                version,
86            });
87        }
88        let flex = is_flexible(version);
89        let mut out = Self::default();
90        if version >= 0 {
91            out.error_code = get_i16(buf)?;
92        }
93        if version >= 0 {
94            out.expiry_timestamp_ms = get_i64(buf)?;
95        }
96        if version >= 0 {
97            out.throttle_time_ms = get_i32(buf)?;
98        }
99        if flex {
100            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
101        }
102        Ok(out)
103    }
104}
105#[cfg(test)]
106impl ExpireDelegationTokenResponse {
107    #[must_use]
108    pub fn populated(version: i16) -> Self {
109        let mut m = Self::default();
110        if version >= 0 {
111            m.error_code = 1i16;
112        }
113        if version >= 0 {
114            m.expiry_timestamp_ms = 1i64;
115        }
116        if version >= 0 {
117            m.throttle_time_ms = 1i32;
118        }
119        m
120    }
121}