kafka_protocol/messages/
get_telemetry_subscriptions_request.rs

1//! GetTelemetrySubscriptionsRequest
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/GetTelemetrySubscriptionsRequest.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 GetTelemetrySubscriptionsRequest {
24    /// Unique id for this client instance, must be set to 0 on the first request.
25    ///
26    /// Supported API versions: 0
27    pub client_instance_id: Uuid,
28
29    /// Other tagged fields
30    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
31}
32
33impl GetTelemetrySubscriptionsRequest {
34    /// Sets `client_instance_id` to the passed value.
35    ///
36    /// Unique id for this client instance, must be set to 0 on the first request.
37    ///
38    /// Supported API versions: 0
39    pub fn with_client_instance_id(mut self, value: Uuid) -> Self {
40        self.client_instance_id = value;
41        self
42    }
43    /// Sets unknown_tagged_fields to the passed value.
44    pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
45        self.unknown_tagged_fields = value;
46        self
47    }
48    /// Inserts an entry into unknown_tagged_fields.
49    pub fn with_unknown_tagged_field(mut self, key: i32, value: Bytes) -> Self {
50        self.unknown_tagged_fields.insert(key, value);
51        self
52    }
53}
54
55#[cfg(feature = "client")]
56impl Encodable for GetTelemetrySubscriptionsRequest {
57    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
58        types::Uuid.encode(buf, &self.client_instance_id)?;
59        let num_tagged_fields = self.unknown_tagged_fields.len();
60        if num_tagged_fields > std::u32::MAX as usize {
61            bail!(
62                "Too many tagged fields to encode ({} fields)",
63                num_tagged_fields
64            );
65        }
66        types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
67
68        write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
69        Ok(())
70    }
71    fn compute_size(&self, version: i16) -> Result<usize> {
72        let mut total_size = 0;
73        total_size += types::Uuid.compute_size(&self.client_instance_id)?;
74        let num_tagged_fields = self.unknown_tagged_fields.len();
75        if num_tagged_fields > std::u32::MAX as usize {
76            bail!(
77                "Too many tagged fields to encode ({} fields)",
78                num_tagged_fields
79            );
80        }
81        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
82
83        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
84        Ok(total_size)
85    }
86}
87
88#[cfg(feature = "broker")]
89impl Decodable for GetTelemetrySubscriptionsRequest {
90    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
91        let client_instance_id = types::Uuid.decode(buf)?;
92        let mut unknown_tagged_fields = BTreeMap::new();
93        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
94        for _ in 0..num_tagged_fields {
95            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
96            let size: u32 = types::UnsignedVarInt.decode(buf)?;
97            let unknown_value = buf.try_get_bytes(size as usize)?;
98            unknown_tagged_fields.insert(tag as i32, unknown_value);
99        }
100        Ok(Self {
101            client_instance_id,
102            unknown_tagged_fields,
103        })
104    }
105}
106
107impl Default for GetTelemetrySubscriptionsRequest {
108    fn default() -> Self {
109        Self {
110            client_instance_id: Uuid::nil(),
111            unknown_tagged_fields: BTreeMap::new(),
112        }
113    }
114}
115
116impl Message for GetTelemetrySubscriptionsRequest {
117    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
118    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
119}
120
121impl HeaderVersion for GetTelemetrySubscriptionsRequest {
122    fn header_version(version: i16) -> i16 {
123        2
124    }
125}