Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, put_i16};
6use crate::primitives::string_bytes::{
7    compact_string_len, get_compact_string_owned, get_string_owned,
8    put_compact_string, put_string, string_len,
9};
10use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
11
12pub const API_KEY: i16 = 17;
13pub const MIN_VERSION: i16 = 0;
14pub const MAX_VERSION: i16 = 1;
15pub const FLEXIBLE_MIN: i16 = 32767;
16
17#[inline]
18fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
19
20#[derive(Debug, Clone, PartialEq, Eq, Default)]
21pub struct SaslHandshakeResponse {
22    pub error_code: i16,
23    pub mechanisms: Vec<String>,
24    pub unknown_tagged_fields: UnknownTaggedFields,
25}
26
27impl Encode for SaslHandshakeResponse {
28    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
29        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
30            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
31        }
32        let flex = is_flexible(version);
33        if version >= 0 { put_i16(buf, self.error_code) }
34        if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.mechanisms).len(), flex); for it in &self.mechanisms { if flex { put_compact_string(buf, &*it) } else { put_string(buf, &*it) }; } } }
35        Ok(())
36    }
37    fn encoded_len(&self, version: i16) -> usize {
38        let flex = is_flexible(version);
39        let mut n: usize = 0;
40        if version >= 0 { n += 2; }
41        if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.mechanisms).len(), flex); let body: usize = (self.mechanisms).iter().map(|it| if flex { compact_string_len(&*it) } else { string_len(&*it) }).sum(); prefix + body }; }
42        n
43    }
44}
45
46impl<'de> Decode<'de> for SaslHandshakeResponse {
47    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
48        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
49            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
50        }
51        let flex = is_flexible(version);
52        let mut out = Self::default();
53        if version >= 0 { out.error_code = get_i16(buf)?; }
54        if version >= 0 { out.mechanisms = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }); } v }; }
55        Ok(out)
56    }
57}
58
59/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
60/// Only includes fields valid for the given version.
61#[must_use]
62#[allow(unused_comparisons)]
63pub fn default_json(version: i16) -> ::serde_json::Value {
64    let mut obj = ::serde_json::Map::new();
65    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
66    obj.insert("mechanisms".to_string(), ::serde_json::Value::Array(vec![]));
67    ::serde_json::Value::Object(obj)
68}