kafka_protocol/messages/
get_telemetry_subscriptions_response.rs

1//! GetTelemetrySubscriptionsResponse
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/GetTelemetrySubscriptionsResponse.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
21#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct GetTelemetrySubscriptionsResponse {
24    /// 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.
25    ///
26    /// Supported API versions: 0
27    pub throttle_time_ms: i32,
28
29    /// The error code, or 0 if there was no error.
30    ///
31    /// Supported API versions: 0
32    pub error_code: i16,
33
34    /// Assigned client instance id if ClientInstanceId was 0 in the request, else 0.
35    ///
36    /// Supported API versions: 0
37    pub client_instance_id: Uuid,
38
39    /// Unique identifier for the current subscription set for this client instance.
40    ///
41    /// Supported API versions: 0
42    pub subscription_id: i32,
43
44    /// Compression types that broker accepts for the PushTelemetryRequest.
45    ///
46    /// Supported API versions: 0
47    pub accepted_compression_types: Vec<i8>,
48
49    /// Configured push interval, which is the lowest configured interval in the current subscription set.
50    ///
51    /// Supported API versions: 0
52    pub push_interval_ms: i32,
53
54    /// The maximum bytes of binary data the broker accepts in PushTelemetryRequest.
55    ///
56    /// Supported API versions: 0
57    pub telemetry_max_bytes: i32,
58
59    /// Flag to indicate monotonic/counter metrics are to be emitted as deltas or cumulative values
60    ///
61    /// Supported API versions: 0
62    pub delta_temporality: bool,
63
64    /// Requested metrics prefix string match. Empty array: No metrics subscribed, Array[0] empty string: All metrics subscribed.
65    ///
66    /// Supported API versions: 0
67    pub requested_metrics: Vec<StrBytes>,
68
69    /// Other tagged fields
70    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
71}
72
73impl GetTelemetrySubscriptionsResponse {
74    /// Sets `throttle_time_ms` to the passed value.
75    ///
76    /// 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.
77    ///
78    /// Supported API versions: 0
79    pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
80        self.throttle_time_ms = value;
81        self
82    }
83    /// Sets `error_code` to the passed value.
84    ///
85    /// The error code, or 0 if there was no error.
86    ///
87    /// Supported API versions: 0
88    pub fn with_error_code(mut self, value: i16) -> Self {
89        self.error_code = value;
90        self
91    }
92    /// Sets `client_instance_id` to the passed value.
93    ///
94    /// Assigned client instance id if ClientInstanceId was 0 in the request, else 0.
95    ///
96    /// Supported API versions: 0
97    pub fn with_client_instance_id(mut self, value: Uuid) -> Self {
98        self.client_instance_id = value;
99        self
100    }
101    /// Sets `subscription_id` to the passed value.
102    ///
103    /// Unique identifier for the current subscription set for this client instance.
104    ///
105    /// Supported API versions: 0
106    pub fn with_subscription_id(mut self, value: i32) -> Self {
107        self.subscription_id = value;
108        self
109    }
110    /// Sets `accepted_compression_types` to the passed value.
111    ///
112    /// Compression types that broker accepts for the PushTelemetryRequest.
113    ///
114    /// Supported API versions: 0
115    pub fn with_accepted_compression_types(mut self, value: Vec<i8>) -> Self {
116        self.accepted_compression_types = value;
117        self
118    }
119    /// Sets `push_interval_ms` to the passed value.
120    ///
121    /// Configured push interval, which is the lowest configured interval in the current subscription set.
122    ///
123    /// Supported API versions: 0
124    pub fn with_push_interval_ms(mut self, value: i32) -> Self {
125        self.push_interval_ms = value;
126        self
127    }
128    /// Sets `telemetry_max_bytes` to the passed value.
129    ///
130    /// The maximum bytes of binary data the broker accepts in PushTelemetryRequest.
131    ///
132    /// Supported API versions: 0
133    pub fn with_telemetry_max_bytes(mut self, value: i32) -> Self {
134        self.telemetry_max_bytes = value;
135        self
136    }
137    /// Sets `delta_temporality` to the passed value.
138    ///
139    /// Flag to indicate monotonic/counter metrics are to be emitted as deltas or cumulative values
140    ///
141    /// Supported API versions: 0
142    pub fn with_delta_temporality(mut self, value: bool) -> Self {
143        self.delta_temporality = value;
144        self
145    }
146    /// Sets `requested_metrics` to the passed value.
147    ///
148    /// Requested metrics prefix string match. Empty array: No metrics subscribed, Array[0] empty string: All metrics subscribed.
149    ///
150    /// Supported API versions: 0
151    pub fn with_requested_metrics(mut self, value: Vec<StrBytes>) -> Self {
152        self.requested_metrics = value;
153        self
154    }
155    /// Sets unknown_tagged_fields to the passed value.
156    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
157        self.unknown_tagged_fields = value;
158        self
159    }
160    /// Inserts an entry into unknown_tagged_fields.
161    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
162        self.unknown_tagged_fields.insert(key, value);
163        self
164    }
165}
166
167#[cfg(feature = "broker")]
168impl Encodable for GetTelemetrySubscriptionsResponse {
169    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
170        types::Int32.encode(buf, &self.throttle_time_ms)?;
171        types::Int16.encode(buf, &self.error_code)?;
172        types::Uuid.encode(buf, &self.client_instance_id)?;
173        types::Int32.encode(buf, &self.subscription_id)?;
174        types::CompactArray(types::Int8).encode(buf, &self.accepted_compression_types)?;
175        types::Int32.encode(buf, &self.push_interval_ms)?;
176        types::Int32.encode(buf, &self.telemetry_max_bytes)?;
177        types::Boolean.encode(buf, &self.delta_temporality)?;
178        types::CompactArray(types::CompactString).encode(buf, &self.requested_metrics)?;
179        let num_tagged_fields = self.unknown_tagged_fields.len();
180        if num_tagged_fields > std::u32::MAX as usize {
181            bail!(
182                "Too many tagged fields to encode ({} fields)",
183                num_tagged_fields
184            );
185        }
186        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
187
188        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
189        Ok(())
190    }
191    fn compute_size(&self, version: i16) -> Result<usize> {
192        let mut total_size = 0;
193        total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
194        total_size += types::Int16.compute_size(&self.error_code)?;
195        total_size += types::Uuid.compute_size(&self.client_instance_id)?;
196        total_size += types::Int32.compute_size(&self.subscription_id)?;
197        total_size +=
198            types::CompactArray(types::Int8).compute_size(&self.accepted_compression_types)?;
199        total_size += types::Int32.compute_size(&self.push_interval_ms)?;
200        total_size += types::Int32.compute_size(&self.telemetry_max_bytes)?;
201        total_size += types::Boolean.compute_size(&self.delta_temporality)?;
202        total_size +=
203            types::CompactArray(types::CompactString).compute_size(&self.requested_metrics)?;
204        let num_tagged_fields = self.unknown_tagged_fields.len();
205        if num_tagged_fields > std::u32::MAX as usize {
206            bail!(
207                "Too many tagged fields to encode ({} fields)",
208                num_tagged_fields
209            );
210        }
211        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
212
213        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
214        Ok(total_size)
215    }
216}
217
218#[cfg(feature = "client")]
219impl Decodable for GetTelemetrySubscriptionsResponse {
220    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
221        let throttle_time_ms = types::Int32.decode(buf)?;
222        let error_code = types::Int16.decode(buf)?;
223        let client_instance_id = types::Uuid.decode(buf)?;
224        let subscription_id = types::Int32.decode(buf)?;
225        let accepted_compression_types = types::CompactArray(types::Int8).decode(buf)?;
226        let push_interval_ms = types::Int32.decode(buf)?;
227        let telemetry_max_bytes = types::Int32.decode(buf)?;
228        let delta_temporality = types::Boolean.decode(buf)?;
229        let requested_metrics = types::CompactArray(types::CompactString).decode(buf)?;
230        let mut unknown_tagged_fields = BTreeMap::new();
231        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
232        for _ in 0..num_tagged_fields {
233            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
234            let size: u32 = types::UnsignedVarInt.decode(buf)?;
235            let unknown_value = buf.try_get_bytes(size as usize)?;
236            unknown_tagged_fields.insert(tag as i32, unknown_value);
237        }
238        Ok(Self {
239            throttle_time_ms,
240            error_code,
241            client_instance_id,
242            subscription_id,
243            accepted_compression_types,
244            push_interval_ms,
245            telemetry_max_bytes,
246            delta_temporality,
247            requested_metrics,
248            unknown_tagged_fields,
249        })
250    }
251}
252
253impl Default for GetTelemetrySubscriptionsResponse {
254    fn default() -> Self {
255        Self {
256            throttle_time_ms: 0,
257            error_code: 0,
258            client_instance_id: Uuid::nil(),
259            subscription_id: 0,
260            accepted_compression_types: Default::default(),
261            push_interval_ms: 0,
262            telemetry_max_bytes: 0,
263            delta_temporality: false,
264            requested_metrics: Default::default(),
265            unknown_tagged_fields: BTreeMap::new(),
266        }
267    }
268}
269
270impl Message for GetTelemetrySubscriptionsResponse {
271    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
272    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
273}
274
275impl HeaderVersion for GetTelemetrySubscriptionsResponse {
276    fn header_version(version: i16) -> i16 {
277        1
278    }
279}