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