Skip to main content

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

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