Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
AlterUserScramCredentialsResponse.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
4use crate::primitives::string_bytes::{
5    compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
6    get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
7    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string, string_len,
8};
9use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
10use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
11use bytes::{Buf, BufMut};
12pub const API_KEY: i16 = 51;
13pub const MIN_VERSION: i16 = 0;
14pub const MAX_VERSION: i16 = 0;
15pub const FLEXIBLE_MIN: i16 = 0;
16#[inline]
17fn is_flexible(version: i16) -> bool {
18    version >= FLEXIBLE_MIN
19}
20#[derive(Debug, Clone, PartialEq, Eq, Default)]
21pub struct AlterUserScramCredentialsResponse {
22    pub throttle_time_ms: i32,
23    pub results: Vec<AlterUserScramCredentialsResult>,
24    pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl Encode for AlterUserScramCredentialsResponse {
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            put_i32(buf, self.throttle_time_ms);
37        }
38        if version >= 0 {
39            {
40                crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
41                for it in &self.results {
42                    it.encode(buf, version)?;
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 += 4;
57        }
58        if version >= 0 {
59            n += {
60                let prefix =
61                    crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
62                let body: usize = (self.results)
63                    .iter()
64                    .map(|it| it.encoded_len(version))
65                    .sum();
66                prefix + body
67            };
68        }
69        if flex {
70            let known_pairs: Vec<(u32, usize)> = Vec::new();
71            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
72        }
73        n
74    }
75}
76impl Decode<'_> for AlterUserScramCredentialsResponse {
77    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
78        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
79            return Err(ProtocolError::UnsupportedVersion {
80                api_key: API_KEY,
81                version,
82            });
83        }
84        let flex = is_flexible(version);
85        let mut out = Self::default();
86        if version >= 0 {
87            out.throttle_time_ms = get_i32(buf)?;
88        }
89        if version >= 0 {
90            out.results = {
91                let n = crate::primitives::array::get_array_len(buf, flex)?;
92                let mut v = Vec::with_capacity(n);
93                for _ in 0..n {
94                    v.push(AlterUserScramCredentialsResult::decode(buf, version)?);
95                }
96                v
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 AlterUserScramCredentialsResponse {
107    #[must_use]
108    pub fn populated(version: i16) -> Self {
109        let mut m = Self::default();
110        if version >= 0 {
111            m.throttle_time_ms = 1i32;
112        }
113        if version >= 0 {
114            m.results = vec![AlterUserScramCredentialsResult::populated(version)];
115        }
116        m
117    }
118}
119#[derive(Debug, Clone, PartialEq, Eq, Default)]
120pub struct AlterUserScramCredentialsResult {
121    pub user: String,
122    pub error_code: i16,
123    pub error_message: Option<String>,
124    pub unknown_tagged_fields: UnknownTaggedFields,
125}
126impl Encode for AlterUserScramCredentialsResult {
127    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
128        let flex = version >= 0;
129        if version >= 0 {
130            if flex {
131                put_compact_string(buf, &self.user);
132            } else {
133                put_string(buf, &self.user);
134            }
135        }
136        if version >= 0 {
137            put_i16(buf, self.error_code);
138        }
139        if version >= 0 {
140            if flex {
141                put_compact_nullable_string(buf, self.error_message.as_deref());
142            } else {
143                put_nullable_string(buf, self.error_message.as_deref());
144            }
145        }
146        if flex {
147            let tagged = WriteTaggedFields::new();
148            tagged.write(buf, &self.unknown_tagged_fields);
149        }
150        Ok(())
151    }
152    fn encoded_len(&self, version: i16) -> usize {
153        let flex = version >= 0;
154        let mut n: usize = 0;
155        if version >= 0 {
156            n += if flex {
157                compact_string_len(&self.user)
158            } else {
159                string_len(&self.user)
160            };
161        }
162        if version >= 0 {
163            n += 2;
164        }
165        if version >= 0 {
166            n += if flex {
167                compact_nullable_string_len(self.error_message.as_deref())
168            } else {
169                nullable_string_len(self.error_message.as_deref())
170            };
171        }
172        if flex {
173            let known_pairs: Vec<(u32, usize)> = Vec::new();
174            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
175        }
176        n
177    }
178}
179impl Decode<'_> for AlterUserScramCredentialsResult {
180    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
181        let flex = version >= 0;
182        let mut out = Self::default();
183        if version >= 0 {
184            out.user = if flex {
185                get_compact_string_owned(buf)?
186            } else {
187                get_string_owned(buf)?
188            };
189        }
190        if version >= 0 {
191            out.error_code = get_i16(buf)?;
192        }
193        if version >= 0 {
194            out.error_message = if flex {
195                get_compact_nullable_string_owned(buf)?
196            } else {
197                get_nullable_string_owned(buf)?
198            };
199        }
200        if flex {
201            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
202        }
203        Ok(out)
204    }
205}
206#[cfg(test)]
207impl AlterUserScramCredentialsResult {
208    #[must_use]
209    pub fn populated(version: i16) -> Self {
210        let mut m = Self::default();
211        if version >= 0 {
212            m.user = "x".to_string();
213        }
214        if version >= 0 {
215            m.error_code = 1i16;
216        }
217        if version >= 0 {
218            m.error_message = Some("x".to_string());
219        }
220        m
221    }
222}
223/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
224/// Only includes fields valid for the given version.
225#[must_use]
226#[allow(unused_comparisons)]
227pub fn default_json(version: i16) -> ::serde_json::Value {
228    let mut obj = ::serde_json::Map::new();
229    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
230    obj.insert("results".to_string(), ::serde_json::Value::Array(vec![]));
231    ::serde_json::Value::Object(obj)
232}