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 crate::primitives::string_bytes::{
4    bytes_len, compact_bytes_len, get_bytes_owned, get_compact_bytes_owned, put_bytes,
5    put_compact_bytes,
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 = 36;
12pub const MIN_VERSION: i16 = 0;
13pub const MAX_VERSION: i16 = 2;
14pub const FLEXIBLE_MIN: i16 = 2;
15
16#[inline]
17fn is_flexible(version: i16) -> bool {
18    version >= FLEXIBLE_MIN
19}
20
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct SaslAuthenticateRequest {
23    pub auth_bytes: ::bytes::Bytes,
24    pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl Encode for SaslAuthenticateRequest {
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            if flex {
37                put_compact_bytes(buf, &self.auth_bytes);
38            } else {
39                put_bytes(buf, &self.auth_bytes);
40            }
41        }
42        if flex {
43            let tagged = WriteTaggedFields::new();
44            tagged.write(buf, &self.unknown_tagged_fields);
45        }
46        Ok(())
47    }
48    fn encoded_len(&self, version: i16) -> usize {
49        let flex = is_flexible(version);
50        let mut n: usize = 0;
51        if version >= 0 {
52            n += if flex {
53                compact_bytes_len(&self.auth_bytes)
54            } else {
55                bytes_len(&self.auth_bytes)
56            };
57        }
58        if flex {
59            let known_pairs: Vec<(u32, usize)> = Vec::new();
60            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
61        }
62        n
63    }
64}
65impl Decode<'_> for SaslAuthenticateRequest {
66    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
67        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
68            return Err(ProtocolError::UnsupportedVersion {
69                api_key: API_KEY,
70                version,
71            });
72        }
73        let flex = is_flexible(version);
74        let mut out = Self::default();
75        if version >= 0 {
76            out.auth_bytes = if flex {
77                get_compact_bytes_owned(buf)?
78            } else {
79                get_bytes_owned(buf)?
80            };
81        }
82        if flex {
83            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
84        }
85        Ok(out)
86    }
87}
88#[cfg(test)]
89impl SaslAuthenticateRequest {
90    #[must_use]
91    pub fn populated(version: i16) -> Self {
92        let mut m = Self::default();
93        if version >= 0 {
94            m.auth_bytes = ::bytes::Bytes::from_static(b"x");
95        }
96        m
97    }
98}
99
100/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
101/// Only includes fields valid for the given version.
102#[must_use]
103#[allow(unused_comparisons)]
104pub fn default_json(version: i16) -> ::serde_json::Value {
105    let mut obj = ::serde_json::Map::new();
106    obj.insert(
107        "authBytes".to_string(),
108        ::serde_json::Value::String(String::new()),
109    );
110    ::serde_json::Value::Object(obj)
111}
112
113impl crate::ProtocolRequest for SaslAuthenticateRequest {
114    const API_KEY: i16 = API_KEY;
115    const MIN_VERSION: i16 = MIN_VERSION;
116    const MAX_VERSION: i16 = MAX_VERSION;
117    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
118    type Response = super::sasl_authenticate_response::SaslAuthenticateResponse;
119}