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