Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
DescribeUserScramCredentialsRequest.owned.rs

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