crabka_protocol/opt/rustwide/workdir/generated/
DescribeTransactionsRequest.borrowed.rs1use crate::primitives::string_bytes::{
4 compact_string_len, put_compact_string, put_string, string_len,
5};
6use crate::primitives::string_bytes_borrowed::{get_compact_string_borrowed, get_string_borrowed};
7use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
8use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
9use bytes::BufMut;
10
11pub const API_KEY: i16 = 65;
12pub const MIN_VERSION: i16 = 0;
13pub const MAX_VERSION: i16 = 0;
14pub const FLEXIBLE_MIN: i16 = 0;
15
16#[inline]
17fn is_flexible(version: i16) -> bool {
18 version >= FLEXIBLE_MIN
19}
20
21#[derive(Debug, Clone, PartialEq, Eq, Default)]
22pub struct DescribeTransactionsRequest<'a> {
23 pub transactional_ids: Vec<&'a str>,
24 pub unknown_tagged_fields: UnknownTaggedFields,
25}
26impl DescribeTransactionsRequest<'_> {
27 pub fn to_owned(
28 &self,
29 ) -> crate::owned::describe_transactions_request::DescribeTransactionsRequest {
30 crate::owned::describe_transactions_request::DescribeTransactionsRequest {
31 transactional_ids: (self.transactional_ids)
32 .iter()
33 .map(std::string::ToString::to_string)
34 .collect(),
35 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
36 }
37 }
38}
39impl Encode for DescribeTransactionsRequest<'_> {
40 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
41 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
42 return Err(ProtocolError::UnsupportedVersion {
43 api_key: API_KEY,
44 version,
45 });
46 }
47 let flex = is_flexible(version);
48 if version >= 0 {
49 {
50 crate::primitives::array::put_array_len(buf, (self.transactional_ids).len(), flex);
51 for it in &self.transactional_ids {
52 if flex {
53 put_compact_string(buf, it);
54 } else {
55 put_string(buf, it);
56 }
57 }
58 }
59 }
60 if flex {
61 let tagged = WriteTaggedFields::new();
62 tagged.write(buf, &self.unknown_tagged_fields);
63 }
64 Ok(())
65 }
66 fn encoded_len(&self, version: i16) -> usize {
67 let flex = is_flexible(version);
68 let mut n: usize = 0;
69 if version >= 0 {
70 n += {
71 let prefix = crate::primitives::array::array_len_prefix_len(
72 (self.transactional_ids).len(),
73 flex,
74 );
75 let body: usize = (self.transactional_ids)
76 .iter()
77 .map(|it| {
78 if flex {
79 compact_string_len(it)
80 } else {
81 string_len(it)
82 }
83 })
84 .sum();
85 prefix + body
86 };
87 }
88 if flex {
89 let known_pairs: Vec<(u32, usize)> = Vec::new();
90 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
91 }
92 n
93 }
94}
95impl<'de> DecodeBorrow<'de> for DescribeTransactionsRequest<'de> {
96 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
97 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
98 return Err(ProtocolError::UnsupportedVersion {
99 api_key: API_KEY,
100 version,
101 });
102 }
103 let flex = is_flexible(version);
104 let mut out = Self::default();
105 if version >= 0 {
106 out.transactional_ids = {
107 let n = crate::primitives::array::get_array_len(buf, flex)?;
108 let mut v = Vec::with_capacity(n);
109 for _ in 0..n {
110 v.push(if flex {
111 get_compact_string_borrowed(buf)?
112 } else {
113 get_string_borrowed(buf)?
114 });
115 }
116 v
117 };
118 }
119 if flex {
120 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
121 }
122 Ok(out)
123 }
124}
125#[cfg(test)]
126impl DescribeTransactionsRequest<'_> {
127 #[must_use]
128 pub fn populated(version: i16) -> Self {
129 let mut m = Self::default();
130 if version >= 0 {
131 m.transactional_ids = vec!["x"];
132 }
133 m
134 }
135}