Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
SaslHandshakeRequest.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        compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
9        put_string, string_len,
10    },
11};
12pub const API_KEY: i16 = 17;
13pub const MIN_VERSION: i16 = 0;
14pub const MAX_VERSION: i16 = 1;
15pub const LATEST_STABLE_VERSION: i16 = 1;
16pub const FLEXIBLE_MIN: i16 = 32767;
17#[inline]
18#[must_use]
19pub fn is_flexible(version: i16) -> bool {
20    version == FLEXIBLE_MIN
21}
22#[derive(Debug, Clone, PartialEq, Eq, Default)]
23pub struct SaslHandshakeRequest {
24    pub mechanism: String,
25    pub unknown_tagged_fields: UnknownTaggedFields,
26}
27impl Encode for SaslHandshakeRequest {
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 {
31                api_key: API_KEY,
32                version,
33            });
34        }
35        let flex = is_flexible(version);
36        if version >= 0 {
37            if flex {
38                let () = put_compact_string(buf, &self.mechanism);
39            } else {
40                let () = put_string(buf, &self.mechanism);
41            }
42        }
43        Ok(())
44    }
45    fn encoded_len(&self, version: i16) -> usize {
46        let flex = is_flexible(version);
47        let mut n: usize = 0;
48        if version >= 0 {
49            n += if flex {
50                compact_string_len(&self.mechanism)
51            } else {
52                string_len(&self.mechanism)
53            };
54        }
55        n
56    }
57}
58impl Decode<'_> for SaslHandshakeRequest {
59    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
60        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
61            return Err(ProtocolError::UnsupportedVersion {
62                api_key: API_KEY,
63                version,
64            });
65        }
66        let flex = is_flexible(version);
67        let mut out = Self::default();
68        if version >= 0 {
69            out.mechanism = if flex {
70                get_compact_string_owned(buf)?
71            } else {
72                get_string_owned(buf)?
73            };
74        }
75        Ok(out)
76    }
77}
78#[cfg(test)]
79impl SaslHandshakeRequest {
80    #[must_use]
81    pub fn populated(version: i16) -> Self {
82        let mut m = Self::default();
83        if version >= 0 {
84            m.mechanism = "x".to_string();
85        }
86        m
87    }
88}
89/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
90/// Only includes fields valid for the given version.
91#[must_use]
92#[allow(unused_comparisons)]
93pub fn default_json(_version: i16) -> ::serde_json::Value {
94    let mut obj = ::serde_json::Map::new();
95    obj.insert(
96        "mechanism".to_string(),
97        ::serde_json::Value::String(String::new()),
98    );
99    ::serde_json::Value::Object(obj)
100}
101impl crate::ProtocolRequest for SaslHandshakeRequest {
102    const API_KEY: i16 = API_KEY;
103    const MIN_VERSION: i16 = MIN_VERSION;
104    const MAX_VERSION: i16 = MAX_VERSION;
105    const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
106    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
107    type Response = super::sasl_handshake_response::SaslHandshakeResponse;
108}