krabka_protocol/opt/rustwide/workdir/generated/
DelegationTokenRecord.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 fixed::{get_i64, put_i64},
9 string_bytes::{
10 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
11 put_string, string_len,
12 },
13 },
14 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
15};
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 0;
18pub const FLEXIBLE_MIN: i16 = 0;
19#[inline]
20#[must_use]
21pub fn is_flexible(version: i16) -> bool {
22 version >= FLEXIBLE_MIN
23}
24#[derive(Debug, Clone, PartialEq, Eq, Default)]
25pub struct DelegationTokenRecord {
26 pub owner: String,
27 pub requester: String,
28 pub renewers: Vec<String>,
29 pub issue_timestamp: i64,
30 pub max_timestamp: i64,
31 pub expiration_timestamp: i64,
32 pub token_id: String,
33 pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl Encode for DelegationTokenRecord {
36 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
37 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
38 return Err(ProtocolError::SchemaMismatch(
39 "DelegationTokenRecord version out of range",
40 ));
41 }
42 let flex = is_flexible(version);
43 if version >= 0 {
44 if flex {
45 let () = put_compact_string(buf, &self.owner);
46 } else {
47 let () = put_string(buf, &self.owner);
48 }
49 }
50 if version >= 0 {
51 if flex {
52 let () = put_compact_string(buf, &self.requester);
53 } else {
54 let () = put_string(buf, &self.requester);
55 }
56 }
57 if version >= 0 {
58 {
59 crate::primitives::array::put_array_len(buf, (self.renewers).len(), flex);
60 for it in &self.renewers {
61 if flex {
62 let () = put_compact_string(buf, it);
63 } else {
64 let () = put_string(buf, it);
65 }
66 }
67 };
68 }
69 if version >= 0 {
70 put_i64(buf, self.issue_timestamp);
71 }
72 if version >= 0 {
73 put_i64(buf, self.max_timestamp);
74 }
75 if version >= 0 {
76 put_i64(buf, self.expiration_timestamp);
77 }
78 if version >= 0 {
79 if flex {
80 let () = put_compact_string(buf, &self.token_id);
81 } else {
82 let () = put_string(buf, &self.token_id);
83 }
84 }
85 if flex {
86 let tagged = WriteTaggedFields::new();
87 tagged.write(buf, &self.unknown_tagged_fields);
88 }
89 Ok(())
90 }
91 fn encoded_len(&self, version: i16) -> usize {
92 let flex = is_flexible(version);
93 let mut n: usize = 0;
94 if version >= 0 {
95 n += if flex {
96 compact_string_len(&self.owner)
97 } else {
98 string_len(&self.owner)
99 };
100 }
101 if version >= 0 {
102 n += if flex {
103 compact_string_len(&self.requester)
104 } else {
105 string_len(&self.requester)
106 };
107 }
108 if version >= 0 {
109 n += {
110 let prefix =
111 crate::primitives::array::array_len_prefix_len((self.renewers).len(), flex);
112 let body: usize = (self.renewers)
113 .iter()
114 .map(|it| {
115 if flex {
116 compact_string_len(it)
117 } else {
118 string_len(it)
119 }
120 })
121 .sum();
122 prefix + body
123 };
124 }
125 if version >= 0 {
126 n += 8;
127 }
128 if version >= 0 {
129 n += 8;
130 }
131 if version >= 0 {
132 n += 8;
133 }
134 if version >= 0 {
135 n += if flex {
136 compact_string_len(&self.token_id)
137 } else {
138 string_len(&self.token_id)
139 };
140 }
141 if flex {
142 let known_pairs: Vec<(u32, usize)> = Vec::new();
143 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
144 }
145 n
146 }
147}
148impl Decode<'_> for DelegationTokenRecord {
149 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
150 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
151 return Err(ProtocolError::SchemaMismatch(
152 "DelegationTokenRecord version out of range",
153 ));
154 }
155 let flex = is_flexible(version);
156 let mut out = Self::default();
157 if version >= 0 {
158 out.owner = if flex {
159 get_compact_string_owned(buf)?
160 } else {
161 get_string_owned(buf)?
162 };
163 }
164 if version >= 0 {
165 out.requester = if flex {
166 get_compact_string_owned(buf)?
167 } else {
168 get_string_owned(buf)?
169 };
170 }
171 if version >= 0 {
172 out.renewers = {
173 let n = crate::primitives::array::get_array_len(buf, flex)?;
174 let mut v = Vec::with_capacity(n);
175 for _ in 0..n {
176 v.push(if flex {
177 get_compact_string_owned(buf)?
178 } else {
179 get_string_owned(buf)?
180 });
181 }
182 v
183 };
184 }
185 if version >= 0 {
186 out.issue_timestamp = get_i64(buf)?;
187 }
188 if version >= 0 {
189 out.max_timestamp = get_i64(buf)?;
190 }
191 if version >= 0 {
192 out.expiration_timestamp = get_i64(buf)?;
193 }
194 if version >= 0 {
195 out.token_id = if flex {
196 get_compact_string_owned(buf)?
197 } else {
198 get_string_owned(buf)?
199 };
200 }
201 if flex {
202 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
203 }
204 Ok(out)
205 }
206}
207#[cfg(test)]
208impl DelegationTokenRecord {
209 #[must_use]
210 pub fn populated(version: i16) -> Self {
211 let mut m = Self::default();
212 if version >= 0 {
213 m.owner = "x".to_string();
214 }
215 if version >= 0 {
216 m.requester = "x".to_string();
217 }
218 if version >= 0 {
219 m.renewers = vec!["x".to_string()];
220 }
221 if version >= 0 {
222 m.issue_timestamp = 1i64;
223 }
224 if version >= 0 {
225 m.max_timestamp = 1i64;
226 }
227 if version >= 0 {
228 m.expiration_timestamp = 1i64;
229 }
230 if version >= 0 {
231 m.token_id = "x".to_string();
232 }
233 m
234 }
235}
236#[must_use]
239#[allow(unused_comparisons)]
240pub fn default_json(_version: i16) -> ::serde_json::Value {
241 let mut obj = ::serde_json::Map::new();
242 obj.insert(
243 "owner".to_string(),
244 ::serde_json::Value::String(String::new()),
245 );
246 obj.insert(
247 "requester".to_string(),
248 ::serde_json::Value::String(String::new()),
249 );
250 obj.insert("renewers".to_string(), ::serde_json::Value::Array(vec![]));
251 obj.insert("issueTimestamp".to_string(), ::serde_json::json!(0));
252 obj.insert("maxTimestamp".to_string(), ::serde_json::json!(0));
253 obj.insert("expirationTimestamp".to_string(), ::serde_json::json!(0));
254 obj.insert(
255 "tokenId".to_string(),
256 ::serde_json::Value::String(String::new()),
257 );
258 ::serde_json::Value::Object(obj)
259}