Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
ExpireDelegationTokenRequest.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_i64, put_i64};
6use crate::primitives::string_bytes::{bytes_len, compact_bytes_len, get_bytes_owned, get_compact_bytes_owned, put_bytes, put_compact_bytes};
7use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
8use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
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
15#[inline]
16fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
17
18#[derive(Debug, Clone, PartialEq, Eq, Default)]
19pub struct ExpireDelegationTokenRequest {
20    pub hmac: ::bytes::Bytes,
21    pub expiry_time_period_ms: i64,
22    pub unknown_tagged_fields: UnknownTaggedFields,
23}
24
25impl Encode for ExpireDelegationTokenRequest {
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 { if flex { put_compact_bytes(buf, &self.hmac) } else { put_bytes(buf, &self.hmac) } }
32        if version >= 0 { put_i64(buf, self.expiry_time_period_ms) }
33        if flex {
34            let tagged = WriteTaggedFields::new();
35            tagged.write(buf, &self.unknown_tagged_fields);
36        }
37        Ok(())
38    }
39    fn encoded_len(&self, version: i16) -> usize {
40        let flex = is_flexible(version);
41        let mut n: usize = 0;
42        if version >= 0 { n += if flex { compact_bytes_len(&self.hmac) } else { bytes_len(&self.hmac) }; }
43        if version >= 0 { n += 8; }
44        if flex {
45            let known_pairs: Vec<(u32, usize)> = Vec::new();
46            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
47        }
48        n
49    }
50}
51
52impl<'de> Decode<'de> for ExpireDelegationTokenRequest {
53    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
54        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
55            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
56        }
57        let flex = is_flexible(version);
58        let mut out = Self::default();
59        if version >= 0 { out.hmac = if flex { get_compact_bytes_owned(buf)? } else { get_bytes_owned(buf)? }; }
60        if version >= 0 { out.expiry_time_period_ms = get_i64(buf)?; }
61        if flex {
62            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
63                Ok(false)
64            })?;
65        }
66        Ok(out)
67    }
68}
69
70/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
71/// Only includes fields valid for the given version.
72#[must_use]
73#[allow(unused_comparisons)]
74pub fn default_json(version: i16) -> ::serde_json::Value {
75    let mut obj = ::serde_json::Map::new();
76    obj.insert("hmac".to_string(), ::serde_json::Value::String(String::new()));
77    obj.insert("expiryTimePeriodMs".to_string(), ::serde_json::json!(0));
78    ::serde_json::Value::Object(obj)
79}
80
81impl crate::ProtocolRequest for ExpireDelegationTokenRequest {
82    const API_KEY: i16 = API_KEY;
83    const MIN_VERSION: i16 = MIN_VERSION;
84    const MAX_VERSION: i16 = MAX_VERSION;
85    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
86    type Response = super::expire_delegation_token_response::ExpireDelegationTokenResponse;
87}