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