Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, 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::primitives::string_bytes::{
9    compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
10    string_len,
11};
12use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14use bytes::{Buf, BufMut};
15pub const API_KEY: i16 = 38;
16pub const MIN_VERSION: i16 = 1;
17pub const MAX_VERSION: i16 = 3;
18pub const FLEXIBLE_MIN: i16 = 2;
19#[inline]
20fn is_flexible(version: i16) -> bool {
21    version >= FLEXIBLE_MIN
22}
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct CreateDelegationTokenResponse {
25    pub error_code: i16,
26    pub principal_type: String,
27    pub principal_name: String,
28    pub token_requester_principal_type: String,
29    pub token_requester_principal_name: String,
30    pub issue_timestamp_ms: i64,
31    pub expiry_timestamp_ms: i64,
32    pub max_timestamp_ms: i64,
33    pub token_id: String,
34    pub hmac: ::bytes::Bytes,
35    pub throttle_time_ms: i32,
36    pub unknown_tagged_fields: UnknownTaggedFields,
37}
38impl Encode for CreateDelegationTokenResponse {
39    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
40        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
41            return Err(ProtocolError::UnsupportedVersion {
42                api_key: API_KEY,
43                version,
44            });
45        }
46        let flex = is_flexible(version);
47        if version >= 0 {
48            put_i16(buf, self.error_code);
49        }
50        if version >= 0 {
51            if flex {
52                put_compact_string(buf, &self.principal_type);
53            } else {
54                put_string(buf, &self.principal_type);
55            }
56        }
57        if version >= 0 {
58            if flex {
59                put_compact_string(buf, &self.principal_name);
60            } else {
61                put_string(buf, &self.principal_name);
62            }
63        }
64        if version >= 3 {
65            if flex {
66                put_compact_string(buf, &self.token_requester_principal_type);
67            } else {
68                put_string(buf, &self.token_requester_principal_type);
69            }
70        }
71        if version >= 3 {
72            if flex {
73                put_compact_string(buf, &self.token_requester_principal_name);
74            } else {
75                put_string(buf, &self.token_requester_principal_name);
76            }
77        }
78        if version >= 0 {
79            put_i64(buf, self.issue_timestamp_ms);
80        }
81        if version >= 0 {
82            put_i64(buf, self.expiry_timestamp_ms);
83        }
84        if version >= 0 {
85            put_i64(buf, self.max_timestamp_ms);
86        }
87        if version >= 0 {
88            if flex {
89                put_compact_string(buf, &self.token_id);
90            } else {
91                put_string(buf, &self.token_id);
92            }
93        }
94        if version >= 0 {
95            if flex {
96                put_compact_bytes(buf, &self.hmac);
97            } else {
98                put_bytes(buf, &self.hmac);
99            }
100        }
101        if version >= 0 {
102            put_i32(buf, self.throttle_time_ms);
103        }
104        if flex {
105            let tagged = WriteTaggedFields::new();
106            tagged.write(buf, &self.unknown_tagged_fields);
107        }
108        Ok(())
109    }
110    fn encoded_len(&self, version: i16) -> usize {
111        let flex = is_flexible(version);
112        let mut n: usize = 0;
113        if version >= 0 {
114            n += 2;
115        }
116        if version >= 0 {
117            n += if flex {
118                compact_string_len(&self.principal_type)
119            } else {
120                string_len(&self.principal_type)
121            };
122        }
123        if version >= 0 {
124            n += if flex {
125                compact_string_len(&self.principal_name)
126            } else {
127                string_len(&self.principal_name)
128            };
129        }
130        if version >= 3 {
131            n += if flex {
132                compact_string_len(&self.token_requester_principal_type)
133            } else {
134                string_len(&self.token_requester_principal_type)
135            };
136        }
137        if version >= 3 {
138            n += if flex {
139                compact_string_len(&self.token_requester_principal_name)
140            } else {
141                string_len(&self.token_requester_principal_name)
142            };
143        }
144        if version >= 0 {
145            n += 8;
146        }
147        if version >= 0 {
148            n += 8;
149        }
150        if version >= 0 {
151            n += 8;
152        }
153        if version >= 0 {
154            n += if flex {
155                compact_string_len(&self.token_id)
156            } else {
157                string_len(&self.token_id)
158            };
159        }
160        if version >= 0 {
161            n += if flex {
162                compact_bytes_len(&self.hmac)
163            } else {
164                bytes_len(&self.hmac)
165            };
166        }
167        if version >= 0 {
168            n += 4;
169        }
170        if flex {
171            let known_pairs: Vec<(u32, usize)> = Vec::new();
172            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
173        }
174        n
175    }
176}
177impl Decode<'_> for CreateDelegationTokenResponse {
178    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
179        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
180            return Err(ProtocolError::UnsupportedVersion {
181                api_key: API_KEY,
182                version,
183            });
184        }
185        let flex = is_flexible(version);
186        let mut out = Self::default();
187        if version >= 0 {
188            out.error_code = get_i16(buf)?;
189        }
190        if version >= 0 {
191            out.principal_type = if flex {
192                get_compact_string_owned(buf)?
193            } else {
194                get_string_owned(buf)?
195            };
196        }
197        if version >= 0 {
198            out.principal_name = if flex {
199                get_compact_string_owned(buf)?
200            } else {
201                get_string_owned(buf)?
202            };
203        }
204        if version >= 3 {
205            out.token_requester_principal_type = if flex {
206                get_compact_string_owned(buf)?
207            } else {
208                get_string_owned(buf)?
209            };
210        }
211        if version >= 3 {
212            out.token_requester_principal_name = if flex {
213                get_compact_string_owned(buf)?
214            } else {
215                get_string_owned(buf)?
216            };
217        }
218        if version >= 0 {
219            out.issue_timestamp_ms = get_i64(buf)?;
220        }
221        if version >= 0 {
222            out.expiry_timestamp_ms = get_i64(buf)?;
223        }
224        if version >= 0 {
225            out.max_timestamp_ms = get_i64(buf)?;
226        }
227        if version >= 0 {
228            out.token_id = if flex {
229                get_compact_string_owned(buf)?
230            } else {
231                get_string_owned(buf)?
232            };
233        }
234        if version >= 0 {
235            out.hmac = if flex {
236                get_compact_bytes_owned(buf)?
237            } else {
238                get_bytes_owned(buf)?
239            };
240        }
241        if version >= 0 {
242            out.throttle_time_ms = get_i32(buf)?;
243        }
244        if flex {
245            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
246        }
247        Ok(out)
248    }
249}
250#[cfg(test)]
251impl CreateDelegationTokenResponse {
252    #[must_use]
253    pub fn populated(version: i16) -> Self {
254        let mut m = Self::default();
255        if version >= 0 {
256            m.error_code = 1i16;
257        }
258        if version >= 0 {
259            m.principal_type = "x".to_string();
260        }
261        if version >= 0 {
262            m.principal_name = "x".to_string();
263        }
264        if version >= 3 {
265            m.token_requester_principal_type = "x".to_string();
266        }
267        if version >= 3 {
268            m.token_requester_principal_name = "x".to_string();
269        }
270        if version >= 0 {
271            m.issue_timestamp_ms = 1i64;
272        }
273        if version >= 0 {
274            m.expiry_timestamp_ms = 1i64;
275        }
276        if version >= 0 {
277            m.max_timestamp_ms = 1i64;
278        }
279        if version >= 0 {
280            m.token_id = "x".to_string();
281        }
282        if version >= 0 {
283            m.hmac = ::bytes::Bytes::from_static(b"x");
284        }
285        if version >= 0 {
286            m.throttle_time_ms = 1i32;
287        }
288        m
289    }
290}
291/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
292/// Only includes fields valid for the given version.
293#[must_use]
294#[allow(unused_comparisons)]
295pub fn default_json(version: i16) -> ::serde_json::Value {
296    let mut obj = ::serde_json::Map::new();
297    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
298    obj.insert(
299        "principalType".to_string(),
300        ::serde_json::Value::String(String::new()),
301    );
302    obj.insert(
303        "principalName".to_string(),
304        ::serde_json::Value::String(String::new()),
305    );
306    if version >= 3 {
307        obj.insert(
308            "tokenRequesterPrincipalType".to_string(),
309            ::serde_json::Value::String(String::new()),
310        );
311    }
312    if version >= 3 {
313        obj.insert(
314            "tokenRequesterPrincipalName".to_string(),
315            ::serde_json::Value::String(String::new()),
316        );
317    }
318    obj.insert("issueTimestampMs".to_string(), ::serde_json::json!(0));
319    obj.insert("expiryTimestampMs".to_string(), ::serde_json::json!(0));
320    obj.insert("maxTimestampMs".to_string(), ::serde_json::json!(0));
321    obj.insert(
322        "tokenId".to_string(),
323        ::serde_json::Value::String(String::new()),
324    );
325    obj.insert(
326        "hmac".to_string(),
327        ::serde_json::Value::String(String::new()),
328    );
329    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
330    ::serde_json::Value::Object(obj)
331}