Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
SaslAuthenticateResponse.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, get_i64, put_i16, put_i64};
6use crate::primitives::string_bytes::{
7    compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
8    get_compact_string_owned, get_nullable_string_owned, get_string_owned, nullable_string_len,
9    put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
10    string_len,
11};
12use crate::primitives::string_bytes::{bytes_len, compact_bytes_len, get_bytes_owned, get_compact_bytes_owned, put_bytes, put_compact_bytes};
13use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
14use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
15
16pub const API_KEY: i16 = 36;
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 2;
19pub const FLEXIBLE_MIN: i16 = 2;
20
21#[inline]
22fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
23
24#[derive(Debug, Clone, PartialEq, Eq, Default)]
25pub struct SaslAuthenticateResponse {
26    pub error_code: i16,
27    pub error_message: Option<String>,
28    pub auth_bytes: ::bytes::Bytes,
29    pub session_lifetime_ms: i64,
30    pub unknown_tagged_fields: UnknownTaggedFields,
31}
32
33impl Encode for SaslAuthenticateResponse {
34    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
35        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
36            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
37        }
38        let flex = is_flexible(version);
39        if version >= 0 { put_i16(buf, self.error_code) }
40        if version >= 0 { if flex { put_compact_nullable_string(buf, self.error_message.as_deref()) } else { put_nullable_string(buf, self.error_message.as_deref()) } }
41        if version >= 0 { if flex { put_compact_bytes(buf, &self.auth_bytes) } else { put_bytes(buf, &self.auth_bytes) } }
42        if version >= 1 { put_i64(buf, self.session_lifetime_ms) }
43        if flex {
44            let tagged = WriteTaggedFields::new();
45            tagged.write(buf, &self.unknown_tagged_fields);
46        }
47        Ok(())
48    }
49    fn encoded_len(&self, version: i16) -> usize {
50        let flex = is_flexible(version);
51        let mut n: usize = 0;
52        if version >= 0 { n += 2; }
53        if version >= 0 { n += if flex { compact_nullable_string_len(self.error_message.as_deref()) } else { nullable_string_len(self.error_message.as_deref()) }; }
54        if version >= 0 { n += if flex { compact_bytes_len(&self.auth_bytes) } else { bytes_len(&self.auth_bytes) }; }
55        if version >= 1 { n += 8; }
56        if flex {
57            let known_pairs: Vec<(u32, usize)> = Vec::new();
58            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
59        }
60        n
61    }
62}
63
64impl<'de> Decode<'de> for SaslAuthenticateResponse {
65    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
66        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
67            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
68        }
69        let flex = is_flexible(version);
70        let mut out = Self::default();
71        if version >= 0 { out.error_code = get_i16(buf)?; }
72        if version >= 0 { out.error_message = if flex { get_compact_nullable_string_owned(buf)? } else { get_nullable_string_owned(buf)? }; }
73        if version >= 0 { out.auth_bytes = if flex { get_compact_bytes_owned(buf)? } else { get_bytes_owned(buf)? }; }
74        if version >= 1 { out.session_lifetime_ms = get_i64(buf)?; }
75        if flex {
76            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
77                Ok(false)
78            })?;
79        }
80        Ok(out)
81    }
82}
83
84/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
85/// Only includes fields valid for the given version.
86#[must_use]
87#[allow(unused_comparisons)]
88pub fn default_json(version: i16) -> ::serde_json::Value {
89    let mut obj = ::serde_json::Map::new();
90    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
91    obj.insert("errorMessage".to_string(), ::serde_json::Value::Null);
92    obj.insert("authBytes".to_string(), ::serde_json::Value::String(String::new()));
93    if version >= 1 {
94        obj.insert("sessionLifetimeMs".to_string(), ::serde_json::json!(0));
95    }
96    ::serde_json::Value::Object(obj)
97}