Skip to main content

odradek_protocol/messages/
api_versions_request.rs

1//! `ApiVersionsRequest` — generated from `schemas/ApiVersionsRequest.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 >= 3
25}
26
27/// `ApiVersionsRequest`, versions 0-4.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct ApiVersionsRequest {
31    /// The name of the client.
32    pub client_software_name: String,
33    /// The version of the client.
34    pub client_software_version: String,
35    /// Tagged fields not (yet) known to this crate, kept raw.
36    pub unknown_tagged_fields: Vec<RawTaggedField>,
37}
38
39impl Default for ApiVersionsRequest {
40    fn default() -> Self {
41        Self {
42            client_software_name: String::new(),
43            client_software_version: String::new(),
44            unknown_tagged_fields: Vec::new(),
45        }
46    }
47}
48
49impl ApiVersionsRequest {
50    /// This message's api key in Kafka's registry.
51    pub const API_KEY: i16 = 18;
52    /// The lowest schema version this snapshot can speak.
53    pub const MIN_VERSION: i16 = 0;
54    /// The highest schema version this snapshot can speak.
55    pub const MAX_VERSION: i16 = 4;
56
57    /// Encode this `ApiVersionsRequest` at `version`.
58    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
59        if version >= 3 {
60            if is_flexible(version) {
61                wire::put_compact_string(buf, &self.client_software_name);
62            } else {
63                wire::put_string(buf, &self.client_software_name)?;
64            }
65        }
66        if version >= 3 {
67            if is_flexible(version) {
68                wire::put_compact_string(buf, &self.client_software_version);
69            } else {
70                wire::put_string(buf, &self.client_software_version)?;
71            }
72        }
73        if is_flexible(version) {
74            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
75        }
76        Ok(())
77    }
78
79    /// Decode one `ApiVersionsRequest`, bounding allocation by the default
80    /// [`Limits`] derived from `buf`'s remaining length.
81    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
82        Self::decode_with_limits(buf, version, Limits::default())
83    }
84
85    /// Decode one `ApiVersionsRequest` under `limits`.
86    pub fn decode_with_limits(
87        buf: &mut impl Buf,
88        version: i16,
89        limits: Limits,
90    ) -> Result<Self, DecodeError> {
91        let mut budget = limits.budget(buf.remaining());
92        Self::decode_with_budget(buf, version, &mut budget)
93    }
94
95    /// Decode one `ApiVersionsRequest` against an existing `budget`.
96    pub fn decode_with_budget(
97        buf: &mut impl Buf,
98        version: i16,
99        budget: &mut Budget,
100    ) -> Result<Self, DecodeError> {
101        let mut this = Self::default();
102        if version >= 3 {
103            this.client_software_name = if is_flexible(version) {
104                wire::get_compact_string(buf)?
105            } else {
106                wire::get_string(buf)?
107            };
108        }
109        if version >= 3 {
110            this.client_software_version = if is_flexible(version) {
111                wire::get_compact_string(buf)?
112            } else {
113                wire::get_string(buf)?
114            };
115        }
116        if is_flexible(version) {
117            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
118        }
119        Ok(this)
120    }
121}
122
123impl crate::Message for ApiVersionsRequest {
124    const API_KEY: i16 = 18;
125    const MIN_VERSION: i16 = 0;
126    const MAX_VERSION: i16 = 4;
127
128    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
129        ApiVersionsRequest::encode(self, buf, version)
130    }
131    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
132        ApiVersionsRequest::decode(buf, version)
133    }
134    fn decode_with_limits(
135        buf: &mut impl Buf,
136        version: i16,
137        limits: Limits,
138    ) -> Result<Self, DecodeError> {
139        ApiVersionsRequest::decode_with_limits(buf, version, limits)
140    }
141}