crabka_protocol/opt/rustwide/workdir/generated/
SaslAuthenticateRequest.owned.rs1use crate::primitives::string_bytes::{
4 bytes_len, compact_bytes_len, get_bytes_owned, get_compact_bytes_owned, put_bytes,
5 put_compact_bytes,
6};
7use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
8use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
9use bytes::{Buf, BufMut};
10pub const API_KEY: i16 = 36;
11pub const MIN_VERSION: i16 = 0;
12pub const MAX_VERSION: i16 = 2;
13pub const FLEXIBLE_MIN: i16 = 2;
14#[inline]
15fn is_flexible(version: i16) -> bool {
16 version >= FLEXIBLE_MIN
17}
18#[derive(Debug, Clone, PartialEq, Eq, Default)]
19pub struct SaslAuthenticateRequest {
20 pub auth_bytes: ::bytes::Bytes,
21 pub unknown_tagged_fields: UnknownTaggedFields,
22}
23impl Encode for SaslAuthenticateRequest {
24 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
25 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
26 return Err(ProtocolError::UnsupportedVersion {
27 api_key: API_KEY,
28 version,
29 });
30 }
31 let flex = is_flexible(version);
32 if version >= 0 {
33 if flex {
34 put_compact_bytes(buf, &self.auth_bytes);
35 } else {
36 put_bytes(buf, &self.auth_bytes);
37 }
38 }
39 if flex {
40 let tagged = WriteTaggedFields::new();
41 tagged.write(buf, &self.unknown_tagged_fields);
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_bytes_len(&self.auth_bytes)
51 } else {
52 bytes_len(&self.auth_bytes)
53 };
54 }
55 if flex {
56 let known_pairs: Vec<(u32, usize)> = Vec::new();
57 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
58 }
59 n
60 }
61}
62impl Decode<'_> for SaslAuthenticateRequest {
63 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
64 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
65 return Err(ProtocolError::UnsupportedVersion {
66 api_key: API_KEY,
67 version,
68 });
69 }
70 let flex = is_flexible(version);
71 let mut out = Self::default();
72 if version >= 0 {
73 out.auth_bytes = if flex {
74 get_compact_bytes_owned(buf)?
75 } else {
76 get_bytes_owned(buf)?
77 };
78 }
79 if flex {
80 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
81 }
82 Ok(out)
83 }
84}
85#[cfg(test)]
86impl SaslAuthenticateRequest {
87 #[must_use]
88 pub fn populated(version: i16) -> Self {
89 let mut m = Self::default();
90 if version >= 0 {
91 m.auth_bytes = ::bytes::Bytes::from_static(b"x");
92 }
93 m
94 }
95}
96#[must_use]
99#[allow(unused_comparisons)]
100pub fn default_json(version: i16) -> ::serde_json::Value {
101 let mut obj = ::serde_json::Map::new();
102 obj.insert(
103 "authBytes".to_string(),
104 ::serde_json::Value::String(String::new()),
105 );
106 ::serde_json::Value::Object(obj)
107}
108impl crate::ProtocolRequest for SaslAuthenticateRequest {
109 const API_KEY: i16 = API_KEY;
110 const MIN_VERSION: i16 = MIN_VERSION;
111 const MAX_VERSION: i16 = MAX_VERSION;
112 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
113 type Response = super::sasl_authenticate_response::SaslAuthenticateResponse;
114}