Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{get_i64, put_i64};
4use crate::primitives::string_bytes::{
5    compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
6    get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
7    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
8};
9use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
10use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
11use bytes::{Buf, BufMut};
12pub const API_KEY: i16 = 38;
13pub const MIN_VERSION: i16 = 1;
14pub const MAX_VERSION: i16 = 3;
15pub const FLEXIBLE_MIN: i16 = 2;
16#[inline]
17fn is_flexible(version: i16) -> bool {
18    version >= FLEXIBLE_MIN
19}
20#[derive(Debug, Clone, PartialEq, Eq, Default)]
21pub struct CreateDelegationTokenRequest {
22    pub owner_principal_type: Option<String>,
23    pub owner_principal_name: Option<String>,
24    pub renewers: Vec<CreatableRenewers>,
25    pub max_lifetime_ms: i64,
26    pub unknown_tagged_fields: UnknownTaggedFields,
27}
28impl Encode for CreateDelegationTokenRequest {
29    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
30        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
31            return Err(ProtocolError::UnsupportedVersion {
32                api_key: API_KEY,
33                version,
34            });
35        }
36        let flex = is_flexible(version);
37        if version >= 3 {
38            if flex {
39                put_compact_nullable_string(buf, self.owner_principal_type.as_deref());
40            } else {
41                put_nullable_string(buf, self.owner_principal_type.as_deref());
42            }
43        }
44        if version >= 3 {
45            if flex {
46                put_compact_nullable_string(buf, self.owner_principal_name.as_deref());
47            } else {
48                put_nullable_string(buf, self.owner_principal_name.as_deref());
49            }
50        }
51        if version >= 0 {
52            {
53                crate::primitives::array::put_array_len(buf, (self.renewers).len(), flex);
54                for it in &self.renewers {
55                    it.encode(buf, version)?;
56                }
57            }
58        }
59        if version >= 0 {
60            put_i64(buf, self.max_lifetime_ms);
61        }
62        if flex {
63            let tagged = WriteTaggedFields::new();
64            tagged.write(buf, &self.unknown_tagged_fields);
65        }
66        Ok(())
67    }
68    fn encoded_len(&self, version: i16) -> usize {
69        let flex = is_flexible(version);
70        let mut n: usize = 0;
71        if version >= 3 {
72            n += if flex {
73                compact_nullable_string_len(self.owner_principal_type.as_deref())
74            } else {
75                nullable_string_len(self.owner_principal_type.as_deref())
76            };
77        }
78        if version >= 3 {
79            n += if flex {
80                compact_nullable_string_len(self.owner_principal_name.as_deref())
81            } else {
82                nullable_string_len(self.owner_principal_name.as_deref())
83            };
84        }
85        if version >= 0 {
86            n += {
87                let prefix =
88                    crate::primitives::array::array_len_prefix_len((self.renewers).len(), flex);
89                let body: usize = (self.renewers)
90                    .iter()
91                    .map(|it| it.encoded_len(version))
92                    .sum();
93                prefix + body
94            };
95        }
96        if version >= 0 {
97            n += 8;
98        }
99        if flex {
100            let known_pairs: Vec<(u32, usize)> = Vec::new();
101            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
102        }
103        n
104    }
105}
106impl Decode<'_> for CreateDelegationTokenRequest {
107    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
108        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
109            return Err(ProtocolError::UnsupportedVersion {
110                api_key: API_KEY,
111                version,
112            });
113        }
114        let flex = is_flexible(version);
115        let mut out = Self::default();
116        if version >= 3 {
117            out.owner_principal_type = if flex {
118                get_compact_nullable_string_owned(buf)?
119            } else {
120                get_nullable_string_owned(buf)?
121            };
122        }
123        if version >= 3 {
124            out.owner_principal_name = if flex {
125                get_compact_nullable_string_owned(buf)?
126            } else {
127                get_nullable_string_owned(buf)?
128            };
129        }
130        if version >= 0 {
131            out.renewers = {
132                let n = crate::primitives::array::get_array_len(buf, flex)?;
133                let mut v = Vec::with_capacity(n);
134                for _ in 0..n {
135                    v.push(CreatableRenewers::decode(buf, version)?);
136                }
137                v
138            };
139        }
140        if version >= 0 {
141            out.max_lifetime_ms = get_i64(buf)?;
142        }
143        if flex {
144            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
145        }
146        Ok(out)
147    }
148}
149#[cfg(test)]
150impl CreateDelegationTokenRequest {
151    #[must_use]
152    pub fn populated(version: i16) -> Self {
153        let mut m = Self::default();
154        if version >= 3 {
155            m.owner_principal_type = Some("x".to_string());
156        }
157        if version >= 3 {
158            m.owner_principal_name = Some("x".to_string());
159        }
160        if version >= 0 {
161            m.renewers = vec![CreatableRenewers::populated(version)];
162        }
163        if version >= 0 {
164            m.max_lifetime_ms = 1i64;
165        }
166        m
167    }
168}
169#[derive(Debug, Clone, PartialEq, Eq, Default)]
170pub struct CreatableRenewers {
171    pub principal_type: String,
172    pub principal_name: String,
173    pub unknown_tagged_fields: UnknownTaggedFields,
174}
175impl Encode for CreatableRenewers {
176    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
177        let flex = version >= 2;
178        if version >= 0 {
179            if flex {
180                put_compact_string(buf, &self.principal_type);
181            } else {
182                put_string(buf, &self.principal_type);
183            }
184        }
185        if version >= 0 {
186            if flex {
187                put_compact_string(buf, &self.principal_name);
188            } else {
189                put_string(buf, &self.principal_name);
190            }
191        }
192        if flex {
193            let tagged = WriteTaggedFields::new();
194            tagged.write(buf, &self.unknown_tagged_fields);
195        }
196        Ok(())
197    }
198    fn encoded_len(&self, version: i16) -> usize {
199        let flex = version >= 2;
200        let mut n: usize = 0;
201        if version >= 0 {
202            n += if flex {
203                compact_string_len(&self.principal_type)
204            } else {
205                string_len(&self.principal_type)
206            };
207        }
208        if version >= 0 {
209            n += if flex {
210                compact_string_len(&self.principal_name)
211            } else {
212                string_len(&self.principal_name)
213            };
214        }
215        if flex {
216            let known_pairs: Vec<(u32, usize)> = Vec::new();
217            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
218        }
219        n
220    }
221}
222impl Decode<'_> for CreatableRenewers {
223    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
224        let flex = version >= 2;
225        let mut out = Self::default();
226        if version >= 0 {
227            out.principal_type = if flex {
228                get_compact_string_owned(buf)?
229            } else {
230                get_string_owned(buf)?
231            };
232        }
233        if version >= 0 {
234            out.principal_name = if flex {
235                get_compact_string_owned(buf)?
236            } else {
237                get_string_owned(buf)?
238            };
239        }
240        if flex {
241            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
242        }
243        Ok(out)
244    }
245}
246#[cfg(test)]
247impl CreatableRenewers {
248    #[must_use]
249    pub fn populated(version: i16) -> Self {
250        let mut m = Self::default();
251        if version >= 0 {
252            m.principal_type = "x".to_string();
253        }
254        if version >= 0 {
255            m.principal_name = "x".to_string();
256        }
257        m
258    }
259}
260/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
261/// Only includes fields valid for the given version.
262#[must_use]
263#[allow(unused_comparisons)]
264pub fn default_json(version: i16) -> ::serde_json::Value {
265    let mut obj = ::serde_json::Map::new();
266    if version >= 3 {
267        obj.insert("ownerPrincipalType".to_string(), ::serde_json::Value::Null);
268    }
269    if version >= 3 {
270        obj.insert("ownerPrincipalName".to_string(), ::serde_json::Value::Null);
271    }
272    obj.insert("renewers".to_string(), ::serde_json::Value::Array(vec![]));
273    obj.insert("maxLifetimeMs".to_string(), ::serde_json::json!(0));
274    ::serde_json::Value::Object(obj)
275}
276impl crate::ProtocolRequest for CreateDelegationTokenRequest {
277    const API_KEY: i16 = API_KEY;
278    const MIN_VERSION: i16 = MIN_VERSION;
279    const MAX_VERSION: i16 = MAX_VERSION;
280    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
281    type Response = super::create_delegation_token_response::CreateDelegationTokenResponse;
282}