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