Skip to main content

odradek_protocol/messages/
sasl_handshake_request.rs

1//! `SaslHandshakeRequest` — generated from `schemas/SaslHandshakeRequest.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    false
25}
26
27/// `SaslHandshakeRequest`, versions 0-1.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct SaslHandshakeRequest {
31    /// The SASL mechanism chosen by the client.
32    pub mechanism: String,
33    /// Tagged fields not (yet) known to this crate, kept raw.
34    pub unknown_tagged_fields: Vec<RawTaggedField>,
35}
36
37impl Default for SaslHandshakeRequest {
38    fn default() -> Self {
39        Self {
40            mechanism: String::new(),
41            unknown_tagged_fields: Vec::new(),
42        }
43    }
44}
45
46impl SaslHandshakeRequest {
47    /// This message's api key in Kafka's registry.
48    pub const API_KEY: i16 = 17;
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 = 1;
53
54    /// Encode this `SaslHandshakeRequest` at `version`.
55    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
56        if is_flexible(version) {
57            wire::put_compact_string(buf, &self.mechanism);
58        } else {
59            wire::put_string(buf, &self.mechanism)?;
60        }
61        if is_flexible(version) {
62            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
63        }
64        Ok(())
65    }
66
67    /// Decode one `SaslHandshakeRequest`, 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 `SaslHandshakeRequest` 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 `SaslHandshakeRequest` 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.mechanism = if is_flexible(version) {
91            wire::get_compact_string(buf)?
92        } else {
93            wire::get_string(buf)?
94        };
95        if is_flexible(version) {
96            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
97        }
98        Ok(this)
99    }
100}
101
102impl crate::Message for SaslHandshakeRequest {
103    const API_KEY: i16 = 17;
104    const MIN_VERSION: i16 = 0;
105    const MAX_VERSION: i16 = 1;
106
107    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
108        SaslHandshakeRequest::encode(self, buf, version)
109    }
110    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
111        SaslHandshakeRequest::decode(buf, version)
112    }
113    fn decode_with_limits(
114        buf: &mut impl Buf,
115        version: i16,
116        limits: Limits,
117    ) -> Result<Self, DecodeError> {
118        SaslHandshakeRequest::decode_with_limits(buf, version, limits)
119    }
120}