kafka_protocol/messages/
sasl_handshake_response.rs1#![allow(unused)]
6
7use std::borrow::Borrow;
8use std::collections::BTreeMap;
9
10use anyhow::{bail, Result};
11use bytes::Bytes;
12use uuid::Uuid;
13
14use crate::protocol::{
15 buf::{ByteBuf, ByteBufMut},
16 compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder,
17 Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange,
18};
19
20#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct SaslHandshakeResponse {
24 pub error_code: i16,
28
29 pub mechanisms: Vec<StrBytes>,
33}
34
35impl SaslHandshakeResponse {
36 pub fn with_error_code(mut self, value: i16) -> Self {
42 self.error_code = value;
43 self
44 }
45 pub fn with_mechanisms(mut self, value: Vec<StrBytes>) -> Self {
51 self.mechanisms = value;
52 self
53 }
54}
55
56#[cfg(feature = "broker")]
57impl Encodable for SaslHandshakeResponse {
58 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
59 if version < 0 || version > 1 {
60 bail!("specified version not supported by this message type");
61 }
62 types::Int16.encode(buf, &self.error_code)?;
63 types::Array(types::String).encode(buf, &self.mechanisms)?;
64
65 Ok(())
66 }
67 fn compute_size(&self, version: i16) -> Result<usize> {
68 let mut total_size = 0;
69 total_size += types::Int16.compute_size(&self.error_code)?;
70 total_size += types::Array(types::String).compute_size(&self.mechanisms)?;
71
72 Ok(total_size)
73 }
74}
75
76#[cfg(feature = "client")]
77impl Decodable for SaslHandshakeResponse {
78 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
79 if version < 0 || version > 1 {
80 bail!("specified version not supported by this message type");
81 }
82 let error_code = types::Int16.decode(buf)?;
83 let mechanisms = types::Array(types::String).decode(buf)?;
84 Ok(Self {
85 error_code,
86 mechanisms,
87 })
88 }
89}
90
91impl Default for SaslHandshakeResponse {
92 fn default() -> Self {
93 Self {
94 error_code: 0,
95 mechanisms: Default::default(),
96 }
97 }
98}
99
100impl Message for SaslHandshakeResponse {
101 const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
102 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
103}
104
105impl HeaderVersion for SaslHandshakeResponse {
106 fn header_version(version: i16) -> i16 {
107 0
108 }
109}