kafka_protocol/messages/
get_telemetry_subscriptions_response.rs1#![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#[non_exhaustive]
22#[derive(Debug, Clone, PartialEq)]
23pub struct GetTelemetrySubscriptionsResponse {
24 pub throttle_time_ms: i32,
28
29 pub error_code: i16,
33
34 pub client_instance_id: Uuid,
38
39 pub subscription_id: i32,
43
44 pub accepted_compression_types: Vec<i8>,
48
49 pub push_interval_ms: i32,
53
54 pub telemetry_max_bytes: i32,
58
59 pub delta_temporality: bool,
63
64 pub requested_metrics: Vec<StrBytes>,
68
69 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
71}
72
73impl GetTelemetrySubscriptionsResponse {
74 pub fn with_throttle_time_ms(mut self, value: i32) -> Self {
80 self.throttle_time_ms = value;
81 self
82 }
83 pub fn with_error_code(mut self, value: i16) -> Self {
89 self.error_code = value;
90 self
91 }
92 pub fn with_client_instance_id(mut self, value: Uuid) -> Self {
98 self.client_instance_id = value;
99 self
100 }
101 pub fn with_subscription_id(mut self, value: i32) -> Self {
107 self.subscription_id = value;
108 self
109 }
110 pub fn with_accepted_compression_types(mut self, value: Vec<i8>) -> Self {
116 self.accepted_compression_types = value;
117 self
118 }
119 pub fn with_push_interval_ms(mut self, value: i32) -> Self {
125 self.push_interval_ms = value;
126 self
127 }
128 pub fn with_telemetry_max_bytes(mut self, value: i32) -> Self {
134 self.telemetry_max_bytes = value;
135 self
136 }
137 pub fn with_delta_temporality(mut self, value: bool) -> Self {
143 self.delta_temporality = value;
144 self
145 }
146 pub fn with_requested_metrics(mut self, value: Vec<StrBytes>) -> Self {
152 self.requested_metrics = value;
153 self
154 }
155 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
157 self.unknown_tagged_fields = value;
158 self
159 }
160 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}