kafka_protocol/messages/
describe_transactions_request.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 DescribeTransactionsRequest {
24 pub transactional_ids: Vec<super::TransactionalId>,
28
29 pub unknown_tagged_fields: BTreeMap<i32, Bytes>,
31}
32
33impl DescribeTransactionsRequest {
34 pub fn with_transactional_ids(mut self, value: Vec<super::TransactionalId>) -> Self {
40 self.transactional_ids = value;
41 self
42 }
43 pub fn with_unknown_tagged_fields(mut self, value: BTreeMap<i32, Bytes>) -> Self {
45 self.unknown_tagged_fields = value;
46 self
47 }
48 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 if version != 0 {
59 bail!("specified version not supported by this message type");
60 }
61 types::CompactArray(types::CompactString).encode(buf, &self.transactional_ids)?;
62 let num_tagged_fields = self.unknown_tagged_fields.len();
63 if num_tagged_fields > std::u32::MAX as usize {
64 bail!(
65 "Too many tagged fields to encode ({} fields)",
66 num_tagged_fields
67 );
68 }
69 types::UnsignedVarInt.encode(buf, num_tagged_fields as u32)?;
70
71 write_unknown_tagged_fields(buf, 0.., &self.unknown_tagged_fields)?;
72 Ok(())
73 }
74 fn compute_size(&self, version: i16) -> Result<usize> {
75 let mut total_size = 0;
76 total_size +=
77 types::CompactArray(types::CompactString).compute_size(&self.transactional_ids)?;
78 let num_tagged_fields = self.unknown_tagged_fields.len();
79 if num_tagged_fields > std::u32::MAX as usize {
80 bail!(
81 "Too many tagged fields to encode ({} fields)",
82 num_tagged_fields
83 );
84 }
85 total_size += types::UnsignedVarInt.compute_size(num_tagged_fields as u32)?;
86
87 total_size += compute_unknown_tagged_fields_size(&self.unknown_tagged_fields)?;
88 Ok(total_size)
89 }
90}
91
92#[cfg(feature = "broker")]
93impl Decodable for DescribeTransactionsRequest {
94 fn decode<B: ByteBuf>(buf: &mut B, version: i16) -> Result<Self> {
95 if version != 0 {
96 bail!("specified version not supported by this message type");
97 }
98 let transactional_ids = types::CompactArray(types::CompactString).decode(buf)?;
99 let mut unknown_tagged_fields = BTreeMap::new();
100 let num_tagged_fields = types::UnsignedVarInt.decode(buf)?;
101 for _ in 0..num_tagged_fields {
102 let tag: u32 = types::UnsignedVarInt.decode(buf)?;
103 let size: u32 = types::UnsignedVarInt.decode(buf)?;
104 let unknown_value = buf.try_get_bytes(size as usize)?;
105 unknown_tagged_fields.insert(tag as i32, unknown_value);
106 }
107 Ok(Self {
108 transactional_ids,
109 unknown_tagged_fields,
110 })
111 }
112}
113
114impl Default for DescribeTransactionsRequest {
115 fn default() -> Self {
116 Self {
117 transactional_ids: Default::default(),
118 unknown_tagged_fields: BTreeMap::new(),
119 }
120 }
121}
122
123impl Message for DescribeTransactionsRequest {
124 const VERSIONS: VersionRange = VersionRange { min: 0, max: 0 };
125 const DEPRECATED_VERSIONS: Option<VersionRange> = None;
126}
127
128impl HeaderVersion for DescribeTransactionsRequest {
129 fn header_version(version: i16) -> i16 {
130 2
131 }
132}