Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
SaslAuthenticateResponse.owned.rs

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