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 types::Int16.encode(buf, &self.error_code)?;
60 types::Array(types::String).encode(buf, &self.mechanisms)?;
61
62 Ok(())
63 }
64 fn compute_size(&self, version: i16) -> Result<usize> {
65 let mut total_size = 0;
66 total_size += types::Int16.compute_size(&self.error_code)?;
67 total_size += types::Array(types::String).compute_size(&self.mechanisms)?;
68
69 Ok(total_size)
70 }
71}
72
73#[cfg(feature = "client")]
74impl Decodable for SaslHandshakeResponse {
75 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
76 let error_code = types::Int16.decode(buf)?;
77 let mechanisms = types::Array(types::String).decode(buf)?;
78 Ok(Self {
79 error_code,
80 mechanisms,
81 })
82 }
83}
84
85impl Default for SaslHandshakeResponse {
86 fn default() -> Self {
87 Self {
88 error_code: 0,
89 mechanisms: Default::default(),
90 }
91 }
92}
93
94impl Message for SaslHandshakeResponse {
95 const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
96 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
97}
98
99impl HeaderVersion for SaslHandshakeResponse {
100 fn header_version(version: i16) -> i16 {
101 0
102 }
103}