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        if version != 0 {
171            bail!("specified version not supported by this message type");
172        }
173        types::Int32.encode(buf, &self.throttle_time_ms)?;
174        types::Int16.encode(buf, &self.error_code)?;
175        types::Uuid.encode(buf, &self.client_instance_id)?;
176        types::Int32.encode(buf, &self.subscription_id)?;
177        types::CompactArray(types::Int8).encode(buf, &self.accepted_compression_types)?;
178        types::Int32.encode(buf, &self.push_interval_ms)?;
179        types::Int32.encode(buf, &self.telemetry_max_bytes)?;
180        types::Boolean.encode(buf, &self.delta_temporality)?;
181        types::CompactArray(types::CompactString).encode(buf, &self.requested_metrics)?;
182        let num_tagged_fields = self.unknown_tagged_fields.len();
183        if num_tagged_fields > std::u32::MAX as usize {
184            bail!(
185                "Too many tagged fields to encode ({} fields)",
186                num_tagged_fields
187            );
188        }
189        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
190
191        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
192        Ok(())
193    }
194    fn compute_size(&self, version: i16) -> Result<usize> {
195        let mut total_size = 0;
196        total_size += types::Int32.compute_size(&self.throttle_time_ms)?;
197        total_size += types::Int16.compute_size(&self.error_code)?;
198        total_size += types::Uuid.compute_size(&self.client_instance_id)?;
199        total_size += types::Int32.compute_size(&self.subscription_id)?;
200        total_size +=
201            types::CompactArray(types::Int8).compute_size(&self.accepted_compression_types)?;
202        total_size += types::Int32.compute_size(&self.push_interval_ms)?;
203        total_size += types::Int32.compute_size(&self.telemetry_max_bytes)?;
204        total_size += types::Boolean.compute_size(&self.delta_temporality)?;
205        total_size +=
206            types::CompactArray(types::CompactString).compute_size(&self.requested_metrics)?;
207        let num_tagged_fields = self.unknown_tagged_fields.len();
208        if num_tagged_fields > std::u32::MAX as usize {
209            bail!(
210                "Too many tagged fields to encode ({} fields)",
211                num_tagged_fields
212            );
213        }
214        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
215
216        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
217        Ok(total_size)
218    }
219}
220
221#[cfg(feature = "client")]
222impl Decodable for GetTelemetrySubscriptionsResponse {
223    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
224        if version != 0 {
225            bail!("specified version not supported by this message type");
226        }
227        let throttle_time_ms = types::Int32.decode(buf)?;
228        let error_code = types::Int16.decode(buf)?;
229        let client_instance_id = types::Uuid.decode(buf)?;
230        let subscription_id = types::Int32.decode(buf)?;
231        let accepted_compression_types = types::CompactArray(types::Int8).decode(buf)?;
232        let push_interval_ms = types::Int32.decode(buf)?;
233        let telemetry_max_bytes = types::Int32.decode(buf)?;
234        let delta_temporality = types::Boolean.decode(buf)?;
235        let requested_metrics = types::CompactArray(types::CompactString).decode(buf)?;
236        let mut unknown_tagged_fields = BTreeMap::new();
237        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
238        for _ in 0..num_tagged_fields {
239            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
240            let size: u32 = types::UnsignedVarInt.decode(buf)?;
241            let unknown_value = buf.try_get_bytes(size as usize)?;
242            unknown_tagged_fields.insert(tag as i32, unknown_value);
243        }
244        Ok(Self {
245            throttle_time_ms,
246            error_code,
247            client_instance_id,
248            subscription_id,
249            accepted_compression_types,
250            push_interval_ms,
251            telemetry_max_bytes,
252            delta_temporality,
253            requested_metrics,
254            unknown_tagged_fields,
255        })
256    }
257}
258
259impl Default for GetTelemetrySubscriptionsResponse {
260    fn default() -> Self {
261        Self {
262            throttle_time_ms: 0,
263            error_code: 0,
264            client_instance_id: Uuid::nil(),
265            subscription_id: 0,
266            accepted_compression_types: Default::default(),
267            push_interval_ms: 0,
268            telemetry_max_bytes: 0,
269            delta_temporality: false,
270            requested_metrics: Default::default(),
271            unknown_tagged_fields: BTreeMap::new(),
272        }
273    }
274}
275
276impl Message for GetTelemetrySubscriptionsResponse {
277    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
278    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
279}
280
281impl HeaderVersion for GetTelemetrySubscriptionsResponse {
282    fn header_version(version: i16) -> i16 {
283        1
284    }
285}