kafka_protocol/messages/
sasl_handshake_request.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 SaslHandshakeRequest {
24 pub mechanism: StrBytes,
28}
29
30impl SaslHandshakeRequest {
31 pub fn with_mechanism(mut self, value: StrBytes) -> Self {
37 self.mechanism = value;
38 self
39 }
40}
41
42#[cfg(feature = "client")]
43impl Encodable for SaslHandshakeRequest {
44 fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
45 if version < 0 || version > 1 {
46 bail!("specified version not supported by this message type");
47 }
48 types::String.encode(buf, &self.mechanism)?;
49
50 Ok(())
51 }
52 fn compute_size(&self, version: i16) -> Result<usize> {
53 let mut total_size = 0;
54 total_size += types::String.compute_size(&self.mechanism)?;
55
56 Ok(total_size)
57 }
58}
59
60#[cfg(feature = "broker")]
61impl Decodable for SaslHandshakeRequest {
62 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
63 if version < 0 || version > 1 {
64 bail!("specified version not supported by this message type");
65 }
66 let mechanism = types::String.decode(buf)?;
67 Ok(Self { mechanism })
68 }
69}
70
71impl Default for SaslHandshakeRequest {
72 fn default() -> Self {
73 Self {
74 mechanism: Default::default(),
75 }
76 }
77}
78
79impl Message for SaslHandshakeRequest {
80 const VERSIONS: VersionRange = VersionRange { min: 0, max: 1 };
81 const DEPRECATED_VERSIONS: Option<VersionRange> = Some(VersionRange { min: 0, max: 0 });
82}
83
84impl HeaderVersion for SaslHandshakeRequest {
85 fn header_version(version: i16) -> i16 {
86 1
87 }
88}