crabka_protocol/opt/rustwide/workdir/generated/
RemoveDelegationTokenRecord.owned.rs1use crate::primitives::string_bytes::{
4 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
5 string_len,
6};
7use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
8use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
9use bytes::{Buf, BufMut};
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 0;
12pub const FLEXIBLE_MIN: i16 = 0;
13#[inline]
14fn is_flexible(version: i16) -> bool {
15 version >= FLEXIBLE_MIN
16}
17#[derive(Debug, Clone, PartialEq, Eq, Default)]
18pub struct RemoveDelegationTokenRecord {
19 pub token_id: String,
20 pub unknown_tagged_fields: UnknownTaggedFields,
21}
22impl Encode for RemoveDelegationTokenRecord {
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::SchemaMismatch(
26 "RemoveDelegationTokenRecord version out of range",
27 ));
28 }
29 let flex = is_flexible(version);
30 if version >= 0 {
31 if flex {
32 put_compact_string(buf, &self.token_id);
33 } else {
34 put_string(buf, &self.token_id);
35 }
36 }
37 if flex {
38 let tagged = WriteTaggedFields::new();
39 tagged.write(buf, &self.unknown_tagged_fields);
40 }
41 Ok(())
42 }
43 fn encoded_len(&self, version: i16) -> usize {
44 let flex = is_flexible(version);
45 let mut n: usize = 0;
46 if version >= 0 {
47 n += if flex {
48 compact_string_len(&self.token_id)
49 } else {
50 string_len(&self.token_id)
51 };
52 }
53 if flex {
54 let known_pairs: Vec<(u32, usize)> = Vec::new();
55 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
56 }
57 n
58 }
59}
60impl Decode<'_> for RemoveDelegationTokenRecord {
61 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
62 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
63 return Err(ProtocolError::SchemaMismatch(
64 "RemoveDelegationTokenRecord version out of range",
65 ));
66 }
67 let flex = is_flexible(version);
68 let mut out = Self::default();
69 if version >= 0 {
70 out.token_id = if flex {
71 get_compact_string_owned(buf)?
72 } else {
73 get_string_owned(buf)?
74 };
75 }
76 if flex {
77 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
78 }
79 Ok(out)
80 }
81}
82#[cfg(test)]
83impl RemoveDelegationTokenRecord {
84 #[must_use]
85 pub fn populated(version: i16) -> Self {
86 let mut m = Self::default();
87 if version >= 0 {
88 m.token_id = "x".to_string();
89 }
90 m
91 }
92}
93#[must_use]
96#[allow(unused_comparisons)]
97pub fn default_json(version: i16) -> ::serde_json::Value {
98 let mut obj = ::serde_json::Map::new();
99 obj.insert(
100 "tokenId".to_string(),
101 ::serde_json::Value::String(String::new()),
102 );
103 ::serde_json::Value::Object(obj)
104}