Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use 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};
10
11pub const API_KEY: i16 = 41;
12pub const MIN_VERSION: i16 = 1;
13pub const MAX_VERSION: i16 = 3;
14pub const FLEXIBLE_MIN: i16 = 2;
15
16#[inline]
17fn is_flexible(version: i16) -> bool {
18    version >= FLEXIBLE_MIN
19}
20
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct DescribeDelegationTokenRequest {
23    pub owners: Option<Vec<DescribeDelegationTokenOwner>>,
24    pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl Encode for DescribeDelegationTokenRequest {
27    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
28        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
29            return Err(ProtocolError::UnsupportedVersion {
30                api_key: API_KEY,
31                version,
32            });
33        }
34        let flex = is_flexible(version);
35        if version >= 0 {
36            {
37                let len = (self.owners).as_ref().map(Vec::len);
38                crate::primitives::array::put_nullable_array_len(buf, len, flex);
39                if let Some(v) = &self.owners {
40                    for it in v {
41                        it.encode(buf, version)?;
42                    }
43                }
44            }
45        }
46        if flex {
47            let tagged = WriteTaggedFields::new();
48            tagged.write(buf, &self.unknown_tagged_fields);
49        }
50        Ok(())
51    }
52    fn encoded_len(&self, version: i16) -> usize {
53        let flex = is_flexible(version);
54        let mut n: usize = 0;
55        if version >= 0 {
56            n += {
57                let opt: Option<&Vec<_>> = (self.owners).as_ref();
58                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
59                    opt.map(std::vec::Vec::len),
60                    flex,
61                );
62                let body: usize =
63                    opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
64                prefix + body
65            };
66        }
67        if flex {
68            let known_pairs: Vec<(u32, usize)> = Vec::new();
69            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
70        }
71        n
72    }
73}
74impl Decode<'_> for DescribeDelegationTokenRequest {
75    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
76        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
77            return Err(ProtocolError::UnsupportedVersion {
78                api_key: API_KEY,
79                version,
80            });
81        }
82        let flex = is_flexible(version);
83        let mut out = Self::default();
84        if version >= 0 {
85            out.owners = {
86                let opt = crate::primitives::array::get_nullable_array_len(buf, flex)?;
87                match opt {
88                    None => None,
89                    Some(n) => {
90                        let mut v = Vec::with_capacity(n);
91                        for _ in 0..n {
92                            v.push(DescribeDelegationTokenOwner::decode(buf, version)?);
93                        }
94                        Some(v)
95                    }
96                }
97            };
98        }
99        if flex {
100            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
101        }
102        Ok(out)
103    }
104}
105#[cfg(test)]
106impl DescribeDelegationTokenRequest {
107    #[must_use]
108    pub fn populated(version: i16) -> Self {
109        let mut m = Self::default();
110        if version >= 0 {
111            m.owners = Some(vec![DescribeDelegationTokenOwner::populated(version)]);
112        }
113        m
114    }
115}
116#[derive(Debug, Clone, PartialEq, Eq, Default)]
117pub struct DescribeDelegationTokenOwner {
118    pub principal_type: String,
119    pub principal_name: String,
120    pub unknown_tagged_fields: UnknownTaggedFields,
121}
122impl Encode for DescribeDelegationTokenOwner {
123    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
124        let flex = version >= 2;
125        if version >= 0 {
126            if flex {
127                put_compact_string(buf, &self.principal_type);
128            } else {
129                put_string(buf, &self.principal_type);
130            }
131        }
132        if version >= 0 {
133            if flex {
134                put_compact_string(buf, &self.principal_name);
135            } else {
136                put_string(buf, &self.principal_name);
137            }
138        }
139        if flex {
140            let tagged = WriteTaggedFields::new();
141            tagged.write(buf, &self.unknown_tagged_fields);
142        }
143        Ok(())
144    }
145    fn encoded_len(&self, version: i16) -> usize {
146        let flex = version >= 2;
147        let mut n: usize = 0;
148        if version >= 0 {
149            n += if flex {
150                compact_string_len(&self.principal_type)
151            } else {
152                string_len(&self.principal_type)
153            };
154        }
155        if version >= 0 {
156            n += if flex {
157                compact_string_len(&self.principal_name)
158            } else {
159                string_len(&self.principal_name)
160            };
161        }
162        if flex {
163            let known_pairs: Vec<(u32, usize)> = Vec::new();
164            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
165        }
166        n
167    }
168}
169impl Decode<'_> for DescribeDelegationTokenOwner {
170    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
171        let flex = version >= 2;
172        let mut out = Self::default();
173        if version >= 0 {
174            out.principal_type = if flex {
175                get_compact_string_owned(buf)?
176            } else {
177                get_string_owned(buf)?
178            };
179        }
180        if version >= 0 {
181            out.principal_name = if flex {
182                get_compact_string_owned(buf)?
183            } else {
184                get_string_owned(buf)?
185            };
186        }
187        if flex {
188            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
189        }
190        Ok(out)
191    }
192}
193#[cfg(test)]
194impl DescribeDelegationTokenOwner {
195    #[must_use]
196    pub fn populated(version: i16) -> Self {
197        let mut m = Self::default();
198        if version >= 0 {
199            m.principal_type = "x".to_string();
200        }
201        if version >= 0 {
202            m.principal_name = "x".to_string();
203        }
204        m
205    }
206}
207
208/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
209/// Only includes fields valid for the given version.
210#[must_use]
211#[allow(unused_comparisons)]
212pub fn default_json(version: i16) -> ::serde_json::Value {
213    let mut obj = ::serde_json::Map::new();
214    obj.insert("owners".to_string(), ::serde_json::Value::Null);
215    ::serde_json::Value::Object(obj)
216}
217
218impl crate::ProtocolRequest for DescribeDelegationTokenRequest {
219    const API_KEY: i16 = API_KEY;
220    const MIN_VERSION: i16 = MIN_VERSION;
221    const MAX_VERSION: i16 = MAX_VERSION;
222    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
223    type Response = super::describe_delegation_token_response::DescribeDelegationTokenResponse;
224}