Skip to main content

kacrab_protocol/generated/
sasl_authenticate_request.rs

1//! Generated from SaslAuthenticateRequest.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 SaslAuthenticateRequestData {
17    /// The SASL authentication bytes from the client, as defined by the SASL mechanism.
18    pub auth_bytes: Bytes,
19    pub _unknown_tagged_fields: Vec<RawTaggedField>,
20}
21impl Default for SaslAuthenticateRequestData {
22    fn default() -> Self {
23        Self {
24            auth_bytes: Bytes::new(),
25            _unknown_tagged_fields: Vec::new(),
26        }
27    }
28}
29impl SaslAuthenticateRequestData {
30    pub fn with_auth_bytes(mut self, value: Bytes) -> Self {
31        self.auth_bytes = value;
32        self
33    }
34    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
35        if version < 0 || version > 2 {
36            return Err(UnsupportedVersion::new(36, version).into());
37        }
38        let auth_bytes;
39        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
40        if version >= 2 {
41            auth_bytes = read_compact_bytes(buf)?;
42        } else {
43            auth_bytes = read_bytes(buf)?;
44        }
45        if version >= 2 {
46            let tagged_fields = read_tagged_fields(buf)?;
47            for field in &tagged_fields {
48                match field.tag {
49                    _ => {
50                        _unknown_tagged_fields.push(field.clone());
51                    },
52                }
53            }
54        }
55        Ok(Self {
56            auth_bytes,
57            _unknown_tagged_fields,
58        })
59    }
60    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
61        if version < 0 || version > 2 {
62            return Err(UnsupportedVersion::new(36, version).into());
63        }
64        if version >= 2 {
65            write_compact_bytes(buf, &self.auth_bytes)?;
66        } else {
67            write_bytes(buf, &self.auth_bytes)?;
68        }
69        if version >= 2 {
70            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
71            all_tags.sort_by_key(|f| f.tag);
72            write_tagged_fields(buf, &all_tags)?;
73        }
74        Ok(())
75    }
76    pub fn encoded_len(&self, version: i16) -> Result<usize> {
77        if version < 0 || version > 2 {
78            return Err(UnsupportedVersion::new(36, version).into());
79        }
80        let mut len: usize = 0;
81        if version >= 2 {
82            len += compact_bytes_len(&self.auth_bytes)?;
83        } else {
84            len += bytes_len(&self.auth_bytes)?;
85        }
86        if version >= 2 {
87            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
88            all_tags.sort_by_key(|f| f.tag);
89            len += tagged_fields_len(&all_tags)?;
90        }
91        Ok(len)
92    }
93}