Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
DescribeUserScramCredentialsRequest.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 = 50;
11pub const MIN_VERSION: i16 = 0;
12pub const MAX_VERSION: i16 = 0;
13pub const FLEXIBLE_MIN: i16 = 0;
14#[inline]
15fn is_flexible(version: i16) -> bool {
16    version >= FLEXIBLE_MIN
17}
18#[derive(Debug, Clone, PartialEq, Eq, Default)]
19pub struct DescribeUserScramCredentialsRequest {
20    pub users: Option<Vec<UserName>>,
21    pub unknown_tagged_fields: UnknownTaggedFields,
22}
23impl Encode for DescribeUserScramCredentialsRequest {
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.users).as_ref().map(Vec::len);
35                crate::primitives::array::put_nullable_array_len(buf, len, flex);
36                if let Some(v) = &self.users {
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.users).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 DescribeUserScramCredentialsRequest {
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.users = {
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(UserName::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 DescribeUserScramCredentialsRequest {
104    #[must_use]
105    pub fn populated(version: i16) -> Self {
106        let mut m = Self::default();
107        if version >= 0 {
108            m.users = Some(vec![UserName::populated(version)]);
109        }
110        m
111    }
112}
113#[derive(Debug, Clone, PartialEq, Eq, Default)]
114pub struct UserName {
115    pub name: String,
116    pub unknown_tagged_fields: UnknownTaggedFields,
117}
118impl Encode for UserName {
119    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
120        let flex = version >= 0;
121        if version >= 0 {
122            if flex {
123                put_compact_string(buf, &self.name);
124            } else {
125                put_string(buf, &self.name);
126            }
127        }
128        if flex {
129            let tagged = WriteTaggedFields::new();
130            tagged.write(buf, &self.unknown_tagged_fields);
131        }
132        Ok(())
133    }
134    fn encoded_len(&self, version: i16) -> usize {
135        let flex = version >= 0;
136        let mut n: usize = 0;
137        if version >= 0 {
138            n += if flex {
139                compact_string_len(&self.name)
140            } else {
141                string_len(&self.name)
142            };
143        }
144        if flex {
145            let known_pairs: Vec<(u32, usize)> = Vec::new();
146            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
147        }
148        n
149    }
150}
151impl Decode<'_> for UserName {
152    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
153        let flex = version >= 0;
154        let mut out = Self::default();
155        if version >= 0 {
156            out.name = if flex {
157                get_compact_string_owned(buf)?
158            } else {
159                get_string_owned(buf)?
160            };
161        }
162        if flex {
163            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
164        }
165        Ok(out)
166    }
167}
168#[cfg(test)]
169impl UserName {
170    #[must_use]
171    pub fn populated(version: i16) -> Self {
172        let mut m = Self::default();
173        if version >= 0 {
174            m.name = "x".to_string();
175        }
176        m
177    }
178}
179/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
180/// Only includes fields valid for the given version.
181#[must_use]
182#[allow(unused_comparisons)]
183pub fn default_json(version: i16) -> ::serde_json::Value {
184    let mut obj = ::serde_json::Map::new();
185    obj.insert("users".to_string(), ::serde_json::Value::Null);
186    ::serde_json::Value::Object(obj)
187}
188impl crate::ProtocolRequest for DescribeUserScramCredentialsRequest {
189    const API_KEY: i16 = API_KEY;
190    const MIN_VERSION: i16 = MIN_VERSION;
191    const MAX_VERSION: i16 = MAX_VERSION;
192    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
193    type Response =
194        super::describe_user_scram_credentials_response::DescribeUserScramCredentialsResponse;
195}