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::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
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 { version >= FLEXIBLE_MIN }
16
17#[derive(Debug, Clone, PartialEq, Eq, Default)]
18pub struct ExpireDelegationTokenResponse {
19    pub error_code: i16,
20    pub expiry_timestamp_ms: i64,
21    pub throttle_time_ms: i32,
22    pub unknown_tagged_fields: UnknownTaggedFields,
23}
24
25impl Encode for ExpireDelegationTokenResponse {
26    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
27        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
28            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
29        }
30        let flex = is_flexible(version);
31        if version >= 0 { put_i16(buf, self.error_code) }
32        if version >= 0 { put_i64(buf, self.expiry_timestamp_ms) }
33        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
34        if flex {
35            let tagged = WriteTaggedFields::new();
36            tagged.write(buf, &self.unknown_tagged_fields);
37        }
38        Ok(())
39    }
40    fn encoded_len(&self, version: i16) -> usize {
41        let flex = is_flexible(version);
42        let mut n: usize = 0;
43        if version >= 0 { n += 2; }
44        if version >= 0 { n += 8; }
45        if version >= 0 { n += 4; }
46        if flex {
47            let known_pairs: Vec<(u32, usize)> = Vec::new();
48            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
49        }
50        n
51    }
52}
53
54impl<'de> Decode<'de> for ExpireDelegationTokenResponse {
55    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
56        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
57            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
58        }
59        let flex = is_flexible(version);
60        let mut out = Self::default();
61        if version >= 0 { out.error_code = get_i16(buf)?; }
62        if version >= 0 { out.expiry_timestamp_ms = get_i64(buf)?; }
63        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
64        if flex {
65            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
66                Ok(false)
67            })?;
68        }
69        Ok(out)
70    }
71}
72
73/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
74/// Only includes fields valid for the given version.
75#[must_use]
76#[allow(unused_comparisons)]
77pub fn default_json(version: i16) -> ::serde_json::Value {
78    let mut obj = ::serde_json::Map::new();
79    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
80    obj.insert("expiryTimestampMs".to_string(), ::serde_json::json!(0));
81    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
82    ::serde_json::Value::Object(obj)
83}