krabka_protocol/opt/rustwide/workdir/generated/
SaslHandshakeRequest.borrowed.rs1use bytes::BufMut;
3
4use crate::{
5 DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6 primitives::{
7 string_bytes::{compact_string_len, put_compact_string, put_string, string_len},
8 string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed},
9 },
10};
11pub const API_KEY: i16 = 17;
12pub const MIN_VERSION: i16 = 0;
13pub const MAX_VERSION: i16 = 1;
14pub const LATEST_STABLE_VERSION: i16 = 1;
15pub const FLEXIBLE_MIN: i16 = 32767;
16#[inline]
17#[must_use]
18pub fn is_flexible(version: i16) -> bool {
19 version == FLEXIBLE_MIN
20}
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct SaslHandshakeRequest<'a> {
23 pub mechanism: &'a str,
24 pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl SaslHandshakeRequest<'_> {
27 #[must_use]
31 pub fn to_owned(&self) -> crate::owned::sasl_handshake_request::SaslHandshakeRequest {
32 crate::owned::sasl_handshake_request::SaslHandshakeRequest {
33 mechanism: (self.mechanism).to_string(),
34 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
35 }
36 }
37}
38impl Encode for SaslHandshakeRequest<'_> {
39 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
40 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
41 return Err(ProtocolError::UnsupportedVersion {
42 api_key: API_KEY,
43 version,
44 });
45 }
46 let flex = is_flexible(version);
47 if version >= 0 {
48 if flex {
49 let () = put_compact_string(buf, self.mechanism);
50 } else {
51 let () = put_string(buf, self.mechanism);
52 }
53 }
54 Ok(())
55 }
56 fn encoded_len(&self, version: i16) -> usize {
57 let flex = is_flexible(version);
58 let mut n: usize = 0;
59 if version >= 0 {
60 n += if flex {
61 compact_string_len(self.mechanism)
62 } else {
63 string_len(self.mechanism)
64 };
65 }
66 n
67 }
68}
69impl<'de> DecodeBorrow<'de> for SaslHandshakeRequest<'de> {
70 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
71 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
72 return Err(ProtocolError::UnsupportedVersion {
73 api_key: API_KEY,
74 version,
75 });
76 }
77 let flex = is_flexible(version);
78 let mut out = Self::default();
79 if version >= 0 {
80 out.mechanism = if flex {
81 get_compact_string_borrowed(buf)?
82 } else {
83 get_string_borrowed(buf)?
84 };
85 }
86 Ok(out)
87 }
88}
89#[cfg(test)]
90impl SaslHandshakeRequest<'_> {
91 #[must_use]
92 pub fn populated(version: i16) -> Self {
93 let mut m = Self::default();
94 if version >= 0 {
95 m.mechanism = "x";
96 }
97 m
98 }
99}