kafka_protocol/messages/
expire_delegation_token_response.rs

1//! ExpireDelegationTokenResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/ExpireDelegationTokenResponse.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: 1-2
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct ExpireDelegationTokenResponse {
24    /// The error code, or 0 if there was no error.
25    ///
26    /// Supported API versions: 1-2
27    pub error_code: i16,
28
29    /// The timestamp in milliseconds at which this token expires.
30    ///
31    /// Supported API versions: 1-2
32    pub expiry_timestamp_ms: i64,
33
34    /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
35    ///
36    /// Supported API versions: 1-2
37    pub throttle_time_ms: i32,
38
39    /// Other tagged fields
40    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
41}
42
43impl ExpireDelegationTokenResponse {
44    /// Sets `error_code` to the passed value.
45    ///
46    /// The error code, or 0 if there was no error.
47    ///
48    /// Supported API versions: 1-2
49    pub fn with_error_code(mut self, value: i16) -> Self {
50        self.error_code = value;
51        self
52    }
53    /// Sets `expiry_timestamp_ms` to the passed value.
54    ///
55    /// The timestamp in milliseconds at which this token expires.
56    ///
57    /// Supported API versions: 1-2
58    pub fn with_expiry_timestamp_ms(mut self, value: i64) -> Self {
59        self.expiry_timestamp_ms = value;
60        self
61    }
62    /// Sets `throttle_time_ms` to the passed value.
63    ///
64    /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
65    ///
66    /// Supported API versions: 1-2
67    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
68        self.throttle_time_ms = value;
69        self
70    }
71    /// Sets unknown_tagged_fields to the passed value.
72    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
73        self.unknown_tagged_fields = value;
74        self
75    }
76    /// Inserts an entry into unknown_tagged_fields.
77    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
78        self.unknown_tagged_fields.insert(key, value);
79        self
80    }
81}
82
83#[cfg(feature = "broker")]
84impl Encodable for ExpireDelegationTokenResponse {
85    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
86        if version < 1 || version > 2 {
87            bail!("specified version not supported by this message type");
88        }
89        types::Int16.encode(buf, &self.error_code)?;
90        types::Int64.encode(buf, &self.expiry_timestamp_ms)?;
91        types::Int32.encode(buf, &self.throttle_time_ms)?;
92        if version >= 2 {
93            let num_tagged_fields = self.unknown_tagged_fields.len();
94            if num_tagged_fields > std::u32::MAX as usize {
95                bail!(
96                    "Too many tagged fields to encode ({} fields)",
97                    num_tagged_fields
98                );
99            }
100            types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
101
102            write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
103        }
104        Ok(())
105    }
106    fn compute_size(&self, version: i16) -> Result<usize> {
107        let mut total_size = 0;
108        total_size += types::Int16.compute_size(&self.error_code)?;
109        total_size += types::Int64.compute_size(&self.expiry_timestamp_ms)?;
110        total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
111        if version >= 2 {
112            let num_tagged_fields = self.unknown_tagged_fields.len();
113            if num_tagged_fields > std::u32::MAX as usize {
114                bail!(
115                    "Too many tagged fields to encode ({} fields)",
116                    num_tagged_fields
117                );
118            }
119            total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
120
121            total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
122        }
123        Ok(total_size)
124    }
125}
126
127#[cfg(feature = "client")]
128impl Decodable for ExpireDelegationTokenResponse {
129    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
130        if version < 1 || version > 2 {
131            bail!("specified version not supported by this message type");
132        }
133        let error_code = types::Int16.decode(buf)?;
134        let expiry_timestamp_ms = types::Int64.decode(buf)?;
135        let throttle_time_ms = types::Int32.decode(buf)?;
136        let mut unknown_tagged_fields = BTreeMap::new();
137        if version >= 2 {
138            let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
139            for _ in 0..num_tagged_fields {
140                let tag: u32 = types::UnsignedVarInt.decode(buf)?;
141                let size: u32 = types::UnsignedVarInt.decode(buf)?;
142                let unknown_value = buf.try_get_bytes(size as usize)?;
143                unknown_tagged_fields.insert(tag as i32, unknown_value);
144            }
145        }
146        Ok(Self {
147            error_code,
148            expiry_timestamp_ms,
149            throttle_time_ms,
150            unknown_tagged_fields,
151        })
152    }
153}
154
155impl Default for ExpireDelegationTokenResponse {
156    fn default() -> Self {
157        Self {
158            error_code: 0,
159            expiry_timestamp_ms: 0,
160            throttle_time_ms: 0,
161            unknown_tagged_fields: BTreeMap::new(),
162        }
163    }
164}
165
166impl Message for ExpireDelegationTokenResponse {
167    const VERSIONS: VersionRange = VersionRange { min: 1, max: 2 };
168    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
169}
170
171impl HeaderVersion for ExpireDelegationTokenResponse {
172    fn header_version(version: i16) -> i16 {
173        if version >= 2 {
174            1
175        } else {
176            0
177        }
178    }
179}