kafka_protocol/messages/
expire_delegation_token_request.rs

1//! ExpireDelegationTokenRequest
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/ExpireDelegationTokenRequest.json).
4// WARNING: the items of this module are generated and should not be edited directly
5#![allow(unused)]
6
7use std::borrow::Borrow;
8use std::collections::BTreeMap;
9
10use anyhow::{bail, Result};
11use bytes::Bytes;
12use uuid::Uuid;
13
14use crate::protocol::{
15    buf::{ByteBuf, ByteBufMut},
16    compute_unknown_tagged_fields_size, types, write_unknown_tagged_fields, Decodable, Decoder,
17    Encodable, Encoder, HeaderVersion, Message, StrBytes, VersionRange,
18};
19
20/// Valid versions: 0-2
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct ExpireDelegationTokenRequest {
24    /// The HMAC of the delegation token to be expired.
25    ///
26    /// Supported API versions: 0-2
27    pub hmac: Bytes,
28
29    /// The expiry time period in milliseconds.
30    ///
31    /// Supported API versions: 0-2
32    pub expiry_time_period_ms: i64,
33
34    /// Other tagged fields
35    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
36}
37
38impl ExpireDelegationTokenRequest {
39    /// Sets `hmac` to the passed value.
40    ///
41    /// The HMAC of the delegation token to be expired.
42    ///
43    /// Supported API versions: 0-2
44    pub fn with_hmac(mut self, value: Bytes) -> Self {
45        self.hmac = value;
46        self
47    }
48    /// Sets `expiry_time_period_ms` to the passed value.
49    ///
50    /// The expiry time period in milliseconds.
51    ///
52    /// Supported API versions: 0-2
53    pub fn with_expiry_time_period_ms(mut self, value: i64) -> Self {
54        self.expiry_time_period_ms = value;
55        self
56    }
57    /// Sets unknown_tagged_fields to the passed value.
58    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
59        self.unknown_tagged_fields = value;
60        self
61    }
62    /// Inserts an entry into unknown_tagged_fields.
63    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
64        self.unknown_tagged_fields.insert(key, value);
65        self
66    }
67}
68
69#[cfg(feature = "client")]
70impl Encodable for ExpireDelegationTokenRequest {
71    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
72        if version >= 2 {
73            types::CompactBytes.encode(buf, &self.hmac)?;
74        } else {
75            types::Bytes.encode(buf, &self.hmac)?;
76        }
77        types::Int64.encode(buf, &self.expiry_time_period_ms)?;
78        if version >= 2 {
79            let num_tagged_fields = self.unknown_tagged_fields.len();
80            if num_tagged_fields > std::u32::MAX as usize {
81                bail!(
82                    "Too many tagged fields to encode ({} fields)",
83                    num_tagged_fields
84                );
85            }
86            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
87
88            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
89        }
90        Ok(())
91    }
92    fn compute_size(&self, version: i16) -> Result<usize> {
93        let mut total_size = 0;
94        if version >= 2 {
95            total_size += types::CompactBytes.compute_size(&self.hmac)?;
96        } else {
97            total_size += types::Bytes.compute_size(&self.hmac)?;
98        }
99        total_size += types::Int64.compute_size(&self.expiry_time_period_ms)?;
100        if version >= 2 {
101            let num_tagged_fields = self.unknown_tagged_fields.len();
102            if num_tagged_fields > std::u32::MAX as usize {
103                bail!(
104                    "Too many tagged fields to encode ({} fields)",
105                    num_tagged_fields
106                );
107            }
108            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
109
110            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
111        }
112        Ok(total_size)
113    }
114}
115
116#[cfg(feature = "broker")]
117impl Decodable for ExpireDelegationTokenRequest {
118    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
119        let hmac = if version >= 2 {
120            types::CompactBytes.decode(buf)?
121        } else {
122            types::Bytes.decode(buf)?
123        };
124        let expiry_time_period_ms = types::Int64.decode(buf)?;
125        let mut unknown_tagged_fields = BTreeMap::new();
126        if version >= 2 {
127            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
128            for _ in 0..num_tagged_fields {
129                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
130                let size: u32 = types::UnsignedVarInt.decode(buf)?;
131                let unknown_value = buf.try_get_bytes(size as usize)?;
132                unknown_tagged_fields.insert(tag as i32, unknown_value);
133            }
134        }
135        Ok(Self {
136            hmac,
137            expiry_time_period_ms,
138            unknown_tagged_fields,
139        })
140    }
141}
142
143impl Default for ExpireDelegationTokenRequest {
144    fn default() -> Self {
145        Self {
146            hmac: Default::default(),
147            expiry_time_period_ms: 0,
148            unknown_tagged_fields: BTreeMap::new(),
149        }
150    }
151}
152
153impl Message for ExpireDelegationTokenRequest {
154    const VERSIONS: VersionRange = VersionRange { min: 0, max: 2 };
155    const DEPRECATED_VERSIONS: Option<VersionRange> = Some(VersionRange { min: 0, max: 0 });
156}
157
158impl HeaderVersion for ExpireDelegationTokenRequest {
159    fn header_version(version: i16) -> i16 {
160        if version >= 2 {
161            2
162        } else {
163            1
164        }
165    }
166}