crabka_protocol/opt/rustwide/workdir/generated/
SaslAuthenticateResponse.owned.rs1use crate::primitives::fixed::{get_i16, get_i64, put_i16, put_i64};
4use crate::primitives::string_bytes::{
5 bytes_len, compact_bytes_len, get_bytes_owned, get_compact_bytes_owned, put_bytes,
6 put_compact_bytes,
7};
8use crate::primitives::string_bytes::{
9 compact_nullable_string_len, get_compact_nullable_string_owned, get_nullable_string_owned,
10 nullable_string_len, put_compact_nullable_string, put_nullable_string,
11};
12use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14use bytes::{Buf, BufMut};
15pub const API_KEY: i16 = 36;
16pub const MIN_VERSION: i16 = 0;
17pub const MAX_VERSION: i16 = 2;
18pub const FLEXIBLE_MIN: i16 = 2;
19#[inline]
20fn is_flexible(version: i16) -> bool {
21 version >= FLEXIBLE_MIN
22}
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct SaslAuthenticateResponse {
25 pub error_code: i16,
26 pub error_message: Option<String>,
27 pub auth_bytes: ::bytes::Bytes,
28 pub session_lifetime_ms: i64,
29 pub unknown_tagged_fields: UnknownTaggedFields,
30}
31impl Encode for SaslAuthenticateResponse {
32 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
33 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
34 return Err(ProtocolError::UnsupportedVersion {
35 api_key: API_KEY,
36 version,
37 });
38 }
39 let flex = is_flexible(version);
40 if version >= 0 {
41 put_i16(buf, self.error_code);
42 }
43 if version >= 0 {
44 if flex {
45 put_compact_nullable_string(buf, self.error_message.as_deref());
46 } else {
47 put_nullable_string(buf, self.error_message.as_deref());
48 }
49 }
50 if version >= 0 {
51 if flex {
52 put_compact_bytes(buf, &self.auth_bytes);
53 } else {
54 put_bytes(buf, &self.auth_bytes);
55 }
56 }
57 if version >= 1 {
58 put_i64(buf, self.session_lifetime_ms);
59 }
60 if flex {
61 let tagged = WriteTaggedFields::new();
62 tagged.write(buf, &self.unknown_tagged_fields);
63 }
64 Ok(())
65 }
66 fn encoded_len(&self, version: i16) -> usize {
67 let flex = is_flexible(version);
68 let mut n: usize = 0;
69 if version >= 0 {
70 n += 2;
71 }
72 if version >= 0 {
73 n += if flex {
74 compact_nullable_string_len(self.error_message.as_deref())
75 } else {
76 nullable_string_len(self.error_message.as_deref())
77 };
78 }
79 if version >= 0 {
80 n += if flex {
81 compact_bytes_len(&self.auth_bytes)
82 } else {
83 bytes_len(&self.auth_bytes)
84 };
85 }
86 if version >= 1 {
87 n += 8;
88 }
89 if flex {
90 let known_pairs: Vec<(u32, usize)> = Vec::new();
91 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
92 }
93 n
94 }
95}
96impl Decode<'_> for SaslAuthenticateResponse {
97 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
98 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
99 return Err(ProtocolError::UnsupportedVersion {
100 api_key: API_KEY,
101 version,
102 });
103 }
104 let flex = is_flexible(version);
105 let mut out = Self::default();
106 if version >= 0 {
107 out.error_code = get_i16(buf)?;
108 }
109 if version >= 0 {
110 out.error_message = if flex {
111 get_compact_nullable_string_owned(buf)?
112 } else {
113 get_nullable_string_owned(buf)?
114 };
115 }
116 if version >= 0 {
117 out.auth_bytes = if flex {
118 get_compact_bytes_owned(buf)?
119 } else {
120 get_bytes_owned(buf)?
121 };
122 }
123 if version >= 1 {
124 out.session_lifetime_ms = get_i64(buf)?;
125 }
126 if flex {
127 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
128 }
129 Ok(out)
130 }
131}
132#[cfg(test)]
133impl SaslAuthenticateResponse {
134 #[must_use]
135 pub fn populated(version: i16) -> Self {
136 let mut m = Self::default();
137 if version >= 0 {
138 m.error_code = 1i16;
139 }
140 if version >= 0 {
141 m.error_message = Some("x".to_string());
142 }
143 if version >= 0 {
144 m.auth_bytes = ::bytes::Bytes::from_static(b"x");
145 }
146 if version >= 1 {
147 m.session_lifetime_ms = 1i64;
148 }
149 m
150 }
151}
152#[must_use]
155#[allow(unused_comparisons)]
156pub fn default_json(version: i16) -> ::serde_json::Value {
157 let mut obj = ::serde_json::Map::new();
158 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
159 obj.insert("errorMessage".to_string(), ::serde_json::Value::Null);
160 obj.insert(
161 "authBytes".to_string(),
162 ::serde_json::Value::String(String::new()),
163 );
164 if version >= 1 {
165 obj.insert("sessionLifetimeMs".to_string(), ::serde_json::json!(0));
166 }
167 ::serde_json::Value::Object(obj)
168}