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