Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ExpireDelegationTokenResponse.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, get_i64, put_i16, put_i32, put_i64};
6use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
7use crate::{Decode, 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 Encode for ExpireDelegationTokenResponse {
27    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
28        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
29            return Err(ProtocolError::UnsupportedVersion {
30                api_key: API_KEY,
31                version,
32            });
33        }
34        let flex = is_flexible(version);
35        if version >= 0 {
36            put_i16(buf, self.error_code);
37        }
38        if version >= 0 {
39            put_i64(buf, self.expiry_timestamp_ms);
40        }
41        if version >= 0 {
42            put_i32(buf, self.throttle_time_ms);
43        }
44        if flex {
45            let tagged = WriteTaggedFields::new();
46            tagged.write(buf, &self.unknown_tagged_fields);
47        }
48        Ok(())
49    }
50    fn encoded_len(&self, version: i16) -> usize {
51        let flex = is_flexible(version);
52        let mut n: usize = 0;
53        if version >= 0 {
54            n += 2;
55        }
56        if version >= 0 {
57            n += 8;
58        }
59        if version >= 0 {
60            n += 4;
61        }
62        if flex {
63            let known_pairs: Vec<(u32, usize)> = Vec::new();
64            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
65        }
66        n
67    }
68}
69impl Decode<'_> for ExpireDelegationTokenResponse {
70    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
71        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
72            return Err(ProtocolError::UnsupportedVersion {
73                api_key: API_KEY,
74                version,
75            });
76        }
77        let flex = is_flexible(version);
78        let mut out = Self::default();
79        if version >= 0 {
80            out.error_code = get_i16(buf)?;
81        }
82        if version >= 0 {
83            out.expiry_timestamp_ms = get_i64(buf)?;
84        }
85        if version >= 0 {
86            out.throttle_time_ms = get_i32(buf)?;
87        }
88        if flex {
89            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
90        }
91        Ok(out)
92    }
93}
94#[cfg(test)]
95impl ExpireDelegationTokenResponse {
96    #[must_use]
97    pub fn populated(version: i16) -> Self {
98        let mut m = Self::default();
99        if version >= 0 {
100            m.error_code = 1i16;
101        }
102        if version >= 0 {
103            m.expiry_timestamp_ms = 1i64;
104        }
105        if version >= 0 {
106            m.throttle_time_ms = 1i32;
107        }
108        m
109    }
110}
111
112/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
113/// Only includes fields valid for the given version.
114#[must_use]
115#[allow(unused_comparisons)]
116pub fn default_json(version: i16) -> ::serde_json::Value {
117    let mut obj = ::serde_json::Map::new();
118    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
119    obj.insert("expiryTimestampMs".to_string(), ::serde_json::json!(0));
120    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
121    ::serde_json::Value::Object(obj)
122}