Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{get_i64, put_i64};
4use crate::primitives::string_bytes::{
5    bytes_len, compact_bytes_len, get_bytes_owned, get_compact_bytes_owned, put_bytes,
6    put_compact_bytes,
7};
8use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
9use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
10use bytes::{Buf, BufMut};
11pub const API_KEY: i16 = 39;
12pub const MIN_VERSION: i16 = 1;
13pub const MAX_VERSION: i16 = 2;
14pub const FLEXIBLE_MIN: i16 = 2;
15#[inline]
16fn is_flexible(version: i16) -> bool {
17    version >= FLEXIBLE_MIN
18}
19#[derive(Debug, Clone, PartialEq, Eq, Default)]
20pub struct RenewDelegationTokenRequest {
21    pub hmac: ::bytes::Bytes,
22    pub renew_period_ms: i64,
23    pub unknown_tagged_fields: UnknownTaggedFields,
24}
25impl Encode for RenewDelegationTokenRequest {
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 {
29                api_key: API_KEY,
30                version,
31            });
32        }
33        let flex = is_flexible(version);
34        if version >= 0 {
35            if flex {
36                put_compact_bytes(buf, &self.hmac);
37            } else {
38                put_bytes(buf, &self.hmac);
39            }
40        }
41        if version >= 0 {
42            put_i64(buf, self.renew_period_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 += if flex {
55                compact_bytes_len(&self.hmac)
56            } else {
57                bytes_len(&self.hmac)
58            };
59        }
60        if version >= 0 {
61            n += 8;
62        }
63        if flex {
64            let known_pairs: Vec<(u32, usize)> = Vec::new();
65            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
66        }
67        n
68    }
69}
70impl Decode<'_> for RenewDelegationTokenRequest {
71    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
72        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
73            return Err(ProtocolError::UnsupportedVersion {
74                api_key: API_KEY,
75                version,
76            });
77        }
78        let flex = is_flexible(version);
79        let mut out = Self::default();
80        if version >= 0 {
81            out.hmac = if flex {
82                get_compact_bytes_owned(buf)?
83            } else {
84                get_bytes_owned(buf)?
85            };
86        }
87        if version >= 0 {
88            out.renew_period_ms = get_i64(buf)?;
89        }
90        if flex {
91            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
92        }
93        Ok(out)
94    }
95}
96#[cfg(test)]
97impl RenewDelegationTokenRequest {
98    #[must_use]
99    pub fn populated(version: i16) -> Self {
100        let mut m = Self::default();
101        if version >= 0 {
102            m.hmac = ::bytes::Bytes::from_static(b"x");
103        }
104        if version >= 0 {
105            m.renew_period_ms = 1i64;
106        }
107        m
108    }
109}
110/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
111/// Only includes fields valid for the given version.
112#[must_use]
113#[allow(unused_comparisons)]
114pub fn default_json(version: i16) -> ::serde_json::Value {
115    let mut obj = ::serde_json::Map::new();
116    obj.insert(
117        "hmac".to_string(),
118        ::serde_json::Value::String(String::new()),
119    );
120    obj.insert("renewPeriodMs".to_string(), ::serde_json::json!(0));
121    ::serde_json::Value::Object(obj)
122}
123impl crate::ProtocolRequest for RenewDelegationTokenRequest {
124    const API_KEY: i16 = API_KEY;
125    const MIN_VERSION: i16 = MIN_VERSION;
126    const MAX_VERSION: i16 = MAX_VERSION;
127    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
128    type Response = super::renew_delegation_token_response::RenewDelegationTokenResponse;
129}