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