kafka_protocol/messages/
sasl_handshake_response.rs

1//! SaslHandshakeResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/SaslHandshakeResponse.json).
4// WARNING: the items of this module are generated and should not be edited directly
5#![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/// Valid versions: 0-1
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct SaslHandshakeResponse {
24    /// The error code, or 0 if there was no error.
25    ///
26    /// Supported API versions: 0-1
27    pub error_code: i16,
28
29    /// The mechanisms enabled in the server.
30    ///
31    /// Supported API versions: 0-1
32    pub mechanisms: Vec<StrBytes>,
33}
34
35impl SaslHandshakeResponse {
36    /// Sets `error_code` to the passed value.
37    ///
38    /// The error code, or 0 if there was no error.
39    ///
40    /// Supported API versions: 0-1
41    pub fn with_error_code(mut self, value: i16) -> Self {
42        self.error_code = value;
43        self
44    }
45    /// Sets `mechanisms` to the passed value.
46    ///
47    /// The mechanisms enabled in the server.
48    ///
49    /// Supported API versions: 0-1
50    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}