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