kafka_protocol/messages/
describe_transactions_request.rs

1//! DescribeTransactionsRequest
2//!
3//! See the schema for this message [here](https://github.com/apache/kafka/blob/trunk/clients/src/main/resources/common/message/DescribeTransactionsRequest.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 DescribeTransactionsRequest {
24    /// Array of transactionalIds to include in describe results. If empty, then no results will be returned.
25    ///
26    /// Supported API versions: 0
27    pub transactional_ids: Vec<super::TransactionalId>,
28
29    /// Other tagged fields
30    pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
31}
32
33impl DescribeTransactionsRequest {
34    /// Sets `transactional_ids` to the passed value.
35    ///
36    /// Array of transactionalIds to include in describe results. If empty, then no results will be returned.
37    ///
38    /// Supported API versions: 0
39    pub fn with_transactional_ids(mut self, value: Vec<super::TransactionalId>) -> Self {
40        self.transactional_ids = 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 DescribeTransactionsRequest {
57    fn encode<B: ByteBufMut>(&self, buf: &mut B, version: i16) -> Result<()> {
58        types::CompactArray(types::CompactString).encode(buf, &self.transactional_ids)?;
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 +=
74            types::CompactArray(types::CompactString).compute_size(&self.transactional_ids)?;
75        let num_tagged_fields = self.unknown_tagged_fields.len();
76        if num_tagged_fields > std::u32::MAX as usize {
77            bail!(
78                "Too many tagged fields to encode ({} fields)",
79                num_tagged_fields
80            );
81        }
82        total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
83
84        total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
85        Ok(total_size)
86    }
87}
88
89#[cfg(feature = "broker")]
90impl Decodable for DescribeTransactionsRequest {
91    fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
92        let transactional_ids = types::CompactArray(types::CompactString).decode(buf)?;
93        let mut unknown_tagged_fields = BTreeMap::new();
94        let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
95        for _ in 0..num_tagged_fields {
96            let tag: u32 = types::UnsignedVarInt.decode(buf)?;
97            let size: u32 = types::UnsignedVarInt.decode(buf)?;
98            let unknown_value = buf.try_get_bytes(size as usize)?;
99            unknown_tagged_fields.insert(tag as i32, unknown_value);
100        }
101        Ok(Self {
102            transactional_ids,
103            unknown_tagged_fields,
104        })
105    }
106}
107
108impl Default for DescribeTransactionsRequest {
109    fn default() -> Self {
110        Self {
111            transactional_ids: Default::default(),
112            unknown_tagged_fields: BTreeMap::new(),
113        }
114    }
115}
116
117impl Message for DescribeTransactionsRequest {
118    const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
119    const DEPRECATED_VERSIONS: Option<VersionRange> = None;
120}
121
122impl HeaderVersion for DescribeTransactionsRequest {
123    fn header_version(version: i16) -> i16 {
124        2
125    }
126}