Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
RenewDelegationTokenResponse.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64};
4use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
5use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
6use bytes::{Buf, BufMut};
7pub const API_KEY: i16 = 39;
8pub const MIN_VERSION: i16 = 1;
9pub const MAX_VERSION: i16 = 2;
10pub const FLEXIBLE_MIN: i16 = 2;
11#[inline]
12fn is_flexible(version: i16) -> bool {
13    version >= FLEXIBLE_MIN
14}
15#[derive(Debug, Clone, PartialEq, Eq, Default)]
16pub struct RenewDelegationTokenResponse {
17    pub error_code: i16,
18    pub expiry_timestamp_ms: i64,
19    pub throttle_time_ms: i32,
20    pub unknown_tagged_fields: UnknownTaggedFields,
21}
22impl Encode for RenewDelegationTokenResponse {
23    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
24        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
25            return Err(ProtocolError::UnsupportedVersion {
26                api_key: API_KEY,
27                version,
28            });
29        }
30        let flex = is_flexible(version);
31        if version >= 0 {
32            put_i16(buf, self.error_code);
33        }
34        if version >= 0 {
35            put_i64(buf, self.expiry_timestamp_ms);
36        }
37        if version >= 0 {
38            put_i32(buf, self.throttle_time_ms);
39        }
40        if flex {
41            let tagged = WriteTaggedFields::new();
42            tagged.write(buf, &self.unknown_tagged_fields);
43        }
44        Ok(())
45    }
46    fn encoded_len(&self, version: i16) -> usize {
47        let flex = is_flexible(version);
48        let mut n: usize = 0;
49        if version >= 0 {
50            n += 2;
51        }
52        if version >= 0 {
53            n += 8;
54        }
55        if version >= 0 {
56            n += 4;
57        }
58        if flex {
59            let known_pairs: Vec<(u32, usize)> = Vec::new();
60            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
61        }
62        n
63    }
64}
65impl Decode<'_> for RenewDelegationTokenResponse {
66    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
67        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
68            return Err(ProtocolError::UnsupportedVersion {
69                api_key: API_KEY,
70                version,
71            });
72        }
73        let flex = is_flexible(version);
74        let mut out = Self::default();
75        if version >= 0 {
76            out.error_code = get_i16(buf)?;
77        }
78        if version >= 0 {
79            out.expiry_timestamp_ms = get_i64(buf)?;
80        }
81        if version >= 0 {
82            out.throttle_time_ms = get_i32(buf)?;
83        }
84        if flex {
85            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
86        }
87        Ok(out)
88    }
89}
90#[cfg(test)]
91impl RenewDelegationTokenResponse {
92    #[must_use]
93    pub fn populated(version: i16) -> Self {
94        let mut m = Self::default();
95        if version >= 0 {
96            m.error_code = 1i16;
97        }
98        if version >= 0 {
99            m.expiry_timestamp_ms = 1i64;
100        }
101        if version >= 0 {
102            m.throttle_time_ms = 1i32;
103        }
104        m
105    }
106}
107/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
108/// Only includes fields valid for the given version.
109#[must_use]
110#[allow(unused_comparisons)]
111pub fn default_json(version: i16) -> ::serde_json::Value {
112    let mut obj = ::serde_json::Map::new();
113    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
114    obj.insert("expiryTimestampMs".to_string(), ::serde_json::json!(0));
115    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
116    ::serde_json::Value::Object(obj)
117}