Skip to main content

odradek_protocol/messages/
sasl_authenticate_request.rs

1//! `SaslAuthenticateRequest` — generated from `schemas/SaslAuthenticateRequest.json`.
2//!
3//! @generated by `cargo xtask codegen`. Do not edit by hand.
4
5#![allow(
6    clippy::field_reassign_with_default,
7    clippy::nonminimal_bool,
8    clippy::derivable_impls,
9    clippy::borrow_deref_ref,
10    clippy::double_parens,
11    unused_parens
12)]
13
14use bytes::{Buf, BufMut};
15
16use crate::budget::{Budget, Limits};
17#[allow(unused_imports)]
18use crate::error::{DecodeError, EncodeError};
19use crate::wire::{self, RawTaggedField};
20
21/// Whether `version` of this message uses the flexible (compact) encoding.
22pub fn is_flexible(version: i16) -> bool {
23    let _ = version;
24    version >= 2
25}
26
27/// `SaslAuthenticateRequest`, versions 0-2.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct SaslAuthenticateRequest {
31    /// The SASL authentication bytes from the client, as defined by the SASL mechanism.
32    pub auth_bytes: bytes::Bytes,
33    /// Tagged fields not (yet) known to this crate, kept raw.
34    pub unknown_tagged_fields: Vec<RawTaggedField>,
35}
36
37impl Default for SaslAuthenticateRequest {
38    fn default() -> Self {
39        Self {
40            auth_bytes: bytes::Bytes::new(),
41            unknown_tagged_fields: Vec::new(),
42        }
43    }
44}
45
46impl SaslAuthenticateRequest {
47    /// This message's api key in Kafka's registry.
48    pub const API_KEY: i16 = 36;
49    /// The lowest schema version this snapshot can speak.
50    pub const MIN_VERSION: i16 = 0;
51    /// The highest schema version this snapshot can speak.
52    pub const MAX_VERSION: i16 = 2;
53
54    /// Encode this `SaslAuthenticateRequest` at `version`.
55    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
56        if is_flexible(version) {
57            wire::put_compact_bytes(buf, &self.auth_bytes);
58        } else {
59            wire::put_bytes(buf, &self.auth_bytes)?;
60        }
61        if is_flexible(version) {
62            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
63        }
64        Ok(())
65    }
66
67    /// Decode one `SaslAuthenticateRequest`, bounding allocation by the default
68    /// [`Limits`] derived from `buf`'s remaining length.
69    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
70        Self::decode_with_limits(buf, version, Limits::default())
71    }
72
73    /// Decode one `SaslAuthenticateRequest` under `limits`.
74    pub fn decode_with_limits(
75        buf: &mut impl Buf,
76        version: i16,
77        limits: Limits,
78    ) -> Result<Self, DecodeError> {
79        let mut budget = limits.budget(buf.remaining());
80        Self::decode_with_budget(buf, version, &mut budget)
81    }
82
83    /// Decode one `SaslAuthenticateRequest` against an existing `budget`.
84    pub fn decode_with_budget(
85        buf: &mut impl Buf,
86        version: i16,
87        budget: &mut Budget,
88    ) -> Result<Self, DecodeError> {
89        let mut this = Self::default();
90        this.auth_bytes = {
91            let raw = if is_flexible(version) {
92                wire::get_compact_nullable_bytes(buf)?
93            } else {
94                wire::get_nullable_bytes(buf)?
95            };
96            match raw {
97                Some(v) => v,
98                None => return Err(DecodeError::InvalidLength(-1)),
99            }
100        };
101        if is_flexible(version) {
102            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
103        }
104        Ok(this)
105    }
106}
107
108impl crate::Message for SaslAuthenticateRequest {
109    const API_KEY: i16 = 36;
110    const MIN_VERSION: i16 = 0;
111    const MAX_VERSION: i16 = 2;
112
113    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
114        SaslAuthenticateRequest::encode(self, buf, version)
115    }
116    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
117        SaslAuthenticateRequest::decode(buf, version)
118    }
119    fn decode_with_limits(
120        buf: &mut impl Buf,
121        version: i16,
122        limits: Limits,
123    ) -> Result<Self, DecodeError> {
124        SaslAuthenticateRequest::decode_with_limits(buf, version, limits)
125    }
126}