Skip to main content

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

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