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