crabka_protocol/opt/rustwide/workdir/generated/
SaslHandshakeRequest.owned.rs1use bytes::{Buf, BufMut};
4use crate::primitives::string_bytes::{
5 compact_string_len, get_compact_string_owned, get_string_owned,
6 put_compact_string, put_string, string_len,
7};
8use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
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 { version >= FLEXIBLE_MIN }
17
18#[derive(Debug, Clone, PartialEq, Eq, Default)]
19pub struct SaslHandshakeRequest {
20 pub mechanism: String,
21 pub unknown_tagged_fields: UnknownTaggedFields,
22}
23
24impl Encode for SaslHandshakeRequest {
25 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
26 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
27 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
28 }
29 let flex = is_flexible(version);
30 if version >= 0 { if flex { put_compact_string(buf, &self.mechanism) } else { put_string(buf, &self.mechanism) } }
31 Ok(())
32 }
33 fn encoded_len(&self, version: i16) -> usize {
34 let flex = is_flexible(version);
35 let mut n: usize = 0;
36 if version >= 0 { n += if flex { compact_string_len(&self.mechanism) } else { string_len(&self.mechanism) }; }
37 n
38 }
39}
40
41impl<'de> Decode<'de> for SaslHandshakeRequest {
42 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
43 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
44 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
45 }
46 let flex = is_flexible(version);
47 let mut out = Self::default();
48 if version >= 0 { out.mechanism = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
49 Ok(out)
50 }
51}
52
53#[must_use]
56#[allow(unused_comparisons)]
57pub fn default_json(version: i16) -> ::serde_json::Value {
58 let mut obj = ::serde_json::Map::new();
59 obj.insert("mechanism".to_string(), ::serde_json::Value::String(String::new()));
60 ::serde_json::Value::Object(obj)
61}
62
63impl crate::ProtocolRequest for SaslHandshakeRequest {
64 const API_KEY: i16 = API_KEY;
65 const MIN_VERSION: i16 = MIN_VERSION;
66 const MAX_VERSION: i16 = MAX_VERSION;
67 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
68 type Response = super::sasl_handshake_response::SaslHandshakeResponse;
69}