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::string_bytes::{
8        compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
9        put_string, string_len,
10    },
11    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
12};
13pub const API_KEY: i16 = 50;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 0;
16pub const LATEST_STABLE_VERSION: i16 = 0;
17pub const FLEXIBLE_MIN: i16 = 0;
18#[inline]
19#[must_use]
20pub fn is_flexible(version: i16) -> bool {
21    version >= FLEXIBLE_MIN
22}
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct DescribeUserScramCredentialsRequest {
25    pub users: Option<Vec<UserName>>,
26    pub unknown_tagged_fields: UnknownTaggedFields,
27}
28impl Default for DescribeUserScramCredentialsRequest {
29    fn default() -> Self {
30        Self {
31            users: Some(Vec::new()),
32            unknown_tagged_fields: UnknownTaggedFields::default(),
33        }
34    }
35}
36impl Encode for DescribeUserScramCredentialsRequest {
37    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
38        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
39            return Err(ProtocolError::UnsupportedVersion {
40                api_key: API_KEY,
41                version,
42            });
43        }
44        let flex = is_flexible(version);
45        if version >= 0 {
46            {
47                let len = (self.users).as_ref().map(Vec::len);
48                crate::primitives::array::put_nullable_array_len(buf, len, flex);
49                if let Some(v) = &self.users {
50                    for it in v {
51                        it.encode(buf, version)?;
52                    }
53                }
54            };
55        }
56        if flex {
57            let tagged = WriteTaggedFields::new();
58            tagged.write(buf, &self.unknown_tagged_fields);
59        }
60        Ok(())
61    }
62    fn encoded_len(&self, version: i16) -> usize {
63        let flex = is_flexible(version);
64        let mut n: usize = 0;
65        if version >= 0 {
66            n += {
67                let opt: Option<&Vec<_>> = (self.users).as_ref();
68                let prefix = crate::primitives::array::nullable_array_len_prefix_len(
69                    opt.map(std::vec::Vec::len),
70                    flex,
71                );
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 = crate::primitives::array::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                let () = put_compact_string(buf, &self.name);
137            } else {
138                let () = 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_string();
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_string(), ::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}