Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4use crate::primitives::string_bytes::{bytes_len, compact_bytes_len, get_bytes_owned, get_compact_bytes_owned, put_bytes, put_compact_bytes};
5use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
6use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
7
8pub const API_KEY: i16 = 36;
9pub const MIN_VERSION: i16 = 0;
10pub const MAX_VERSION: i16 = 2;
11pub const FLEXIBLE_MIN: i16 = 2;
12
13#[inline]
14fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
15
16#[derive(Debug, Clone, PartialEq, Eq, Default)]
17pub struct SaslAuthenticateRequest {
18    pub auth_bytes: ::bytes::Bytes,
19    pub unknown_tagged_fields: UnknownTaggedFields,
20}
21
22impl Encode for SaslAuthenticateRequest {
23    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
24        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
25            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
26        }
27        let flex = is_flexible(version);
28        if version >= 0 { if flex { put_compact_bytes(buf, &self.auth_bytes) } else { put_bytes(buf, &self.auth_bytes) } }
29        if flex {
30            let tagged = WriteTaggedFields::new();
31            tagged.write(buf, &self.unknown_tagged_fields);
32        }
33        Ok(())
34    }
35    fn encoded_len(&self, version: i16) -> usize {
36        let flex = is_flexible(version);
37        let mut n: usize = 0;
38        if version >= 0 { n += if flex { compact_bytes_len(&self.auth_bytes) } else { bytes_len(&self.auth_bytes) }; }
39        if flex {
40            let known_pairs: Vec<(u32, usize)> = Vec::new();
41            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
42        }
43        n
44    }
45}
46
47impl<'de> Decode<'de> for SaslAuthenticateRequest {
48    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
49        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
50            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
51        }
52        let flex = is_flexible(version);
53        let mut out = Self::default();
54        if version >= 0 { out.auth_bytes = if flex { get_compact_bytes_owned(buf)? } else { get_bytes_owned(buf)? }; }
55        if flex {
56            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
57                Ok(false)
58            })?;
59        }
60        Ok(out)
61    }
62}
63
64/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
65/// Only includes fields valid for the given version.
66#[must_use]
67#[allow(unused_comparisons)]
68pub fn default_json(version: i16) -> ::serde_json::Value {
69    let mut obj = ::serde_json::Map::new();
70    obj.insert("authBytes".to_string(), ::serde_json::Value::String(String::new()));
71    ::serde_json::Value::Object(obj)
72}
73
74impl crate::ProtocolRequest for SaslAuthenticateRequest {
75    const API_KEY: i16 = API_KEY;
76    const MIN_VERSION: i16 = MIN_VERSION;
77    const MAX_VERSION: i16 = MAX_VERSION;
78    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
79    type Response = super::sasl_authenticate_response::SaslAuthenticateResponse;
80}