use bytes::Bytes;
use crate::{encode::ToByte, protocol::HeaderRequest};
const API_KEY_METADATA: i16 = 36;
const API_VERSION: i16 = 1;
#[derive(Debug)]
pub struct SaslAuthenticationRequest<'a> {
pub header: HeaderRequest<'a>,
pub auth_bytes: Bytes,
}
impl<'a> SaslAuthenticationRequest<'a> {
pub fn new(correlation_id: i32, client_id: &'a str, auth_bytes: Bytes) -> Self {
let header = HeaderRequest::new(API_KEY_METADATA, API_VERSION, correlation_id, client_id);
Self { header, auth_bytes }
}
}
impl ToByte for SaslAuthenticationRequest<'_> {
fn encode<T: bytes::BufMut>(&self, buffer: &mut T) -> crate::error::Result<()> {
tracing::trace!("Encoding SaslAuthenticationRequest {:?}", self);
self.header.encode(buffer)?;
self.auth_bytes.encode(buffer)?;
Ok(())
}
}