Skip to main content

kacrab_protocol/generated/
sasl_handshake_request.rs

1//! Generated from SaslHandshakeRequest.json - DO NOT EDIT
2#![allow(
3    missing_docs,
4    clippy::all,
5    clippy::pedantic,
6    clippy::nursery,
7    clippy::arithmetic_side_effects,
8    reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9              hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct SaslHandshakeRequestData {
17    /// The SASL mechanism chosen by the client.
18    pub mechanism: KafkaString,
19    pub _unknown_tagged_fields: Vec<RawTaggedField>,
20}
21impl Default for SaslHandshakeRequestData {
22    fn default() -> Self {
23        Self {
24            mechanism: KafkaString::default(),
25            _unknown_tagged_fields: Vec::new(),
26        }
27    }
28}
29impl SaslHandshakeRequestData {
30    pub fn with_mechanism(mut self, value: KafkaString) -> Self {
31        self.mechanism = value;
32        self
33    }
34    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
35        if version < 0 || version > 1 {
36            return Err(UnsupportedVersion::new(17, version).into());
37        }
38        let mechanism;
39        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
40        mechanism = read_string(buf)?;
41        Ok(Self {
42            mechanism,
43            _unknown_tagged_fields,
44        })
45    }
46    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
47        if version < 0 || version > 1 {
48            return Err(UnsupportedVersion::new(17, version).into());
49        }
50        write_string(buf, &self.mechanism)?;
51        Ok(())
52    }
53    pub fn encoded_len(&self, version: i16) -> Result<usize> {
54        if version < 0 || version > 1 {
55            return Err(UnsupportedVersion::new(17, version).into());
56        }
57        let mut len: usize = 0;
58        len += string_len(&self.mechanism)?;
59        Ok(len)
60    }
61}