kacrab_protocol/generated/
write_txn_markers_request.rs1#![allow(
3 missing_docs,
4 clippy::all,
5 clippy::pedantic,
6 clippy::nursery,
7 clippy::arithmetic_side_effects,
8 reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9 hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct WriteTxnMarkersRequestData {
17 pub markers: Vec<WritableTxnMarker>,
19 pub _unknown_tagged_fields: Vec<RawTaggedField>,
20}
21impl Default for WriteTxnMarkersRequestData {
22 fn default() -> Self {
23 Self {
24 markers: Vec::new(),
25 _unknown_tagged_fields: Vec::new(),
26 }
27 }
28}
29impl WriteTxnMarkersRequestData {
30 pub fn with_markers(mut self, value: Vec<WritableTxnMarker>) -> Self {
31 self.markers = value;
32 self
33 }
34 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
35 if version < 1 || version > 2 {
36 return Err(UnsupportedVersion::new(27, version).into());
37 }
38 let markers;
39 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
40 markers = {
41 let len = read_compact_array_length(buf)?;
42 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
43 for _ in 0..len {
44 arr.push(WritableTxnMarker::read(buf, version)?);
45 }
46 arr
47 };
48 let tagged_fields = read_tagged_fields(buf)?;
49 for field in &tagged_fields {
50 match field.tag {
51 _ => {
52 _unknown_tagged_fields.push(field.clone());
53 },
54 }
55 }
56 Ok(Self {
57 markers,
58 _unknown_tagged_fields,
59 })
60 }
61 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
62 if version < 1 || version > 2 {
63 return Err(UnsupportedVersion::new(27, version).into());
64 }
65 write_compact_array_length(buf, self.markers.len() as i32);
66 for el in &self.markers {
67 el.write(buf, version)?;
68 }
69 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
70 all_tags.sort_by_key(|f| f.tag);
71 write_tagged_fields(buf, &all_tags)?;
72 Ok(())
73 }
74 pub fn encoded_len(&self, version: i16) -> Result<usize> {
75 if version < 1 || version > 2 {
76 return Err(UnsupportedVersion::new(27, version).into());
77 }
78 let mut len: usize = 0;
79 len += compact_array_length_len(self.markers.len() as i32);
80 for el in &self.markers {
81 len += el.encoded_len(version)?;
82 }
83 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
84 all_tags.sort_by_key(|f| f.tag);
85 len += tagged_fields_len(&all_tags)?;
86 Ok(len)
87 }
88}
89#[derive(Debug, Clone, PartialEq)]
90pub struct WritableTxnMarker {
91 pub producer_id: i64,
93 pub producer_epoch: i16,
95 pub transaction_result: bool,
97 pub topics: Vec<WritableTxnMarkerTopic>,
99 pub coordinator_epoch: i32,
102 pub transaction_version: i8,
104 pub _unknown_tagged_fields: Vec<RawTaggedField>,
105}
106impl Default for WritableTxnMarker {
107 fn default() -> Self {
108 Self {
109 producer_id: 0_i64,
110 producer_epoch: 0_i16,
111 transaction_result: false,
112 topics: Vec::new(),
113 coordinator_epoch: 0_i32,
114 transaction_version: 0i8,
115 _unknown_tagged_fields: Vec::new(),
116 }
117 }
118}
119impl WritableTxnMarker {
120 pub fn with_producer_id(mut self, value: i64) -> Self {
121 self.producer_id = value;
122 self
123 }
124 pub fn with_producer_epoch(mut self, value: i16) -> Self {
125 self.producer_epoch = value;
126 self
127 }
128 pub fn with_transaction_result(mut self, value: bool) -> Self {
129 self.transaction_result = value;
130 self
131 }
132 pub fn with_topics(mut self, value: Vec<WritableTxnMarkerTopic>) -> Self {
133 self.topics = value;
134 self
135 }
136 pub fn with_coordinator_epoch(mut self, value: i32) -> Self {
137 self.coordinator_epoch = value;
138 self
139 }
140 pub fn with_transaction_version(mut self, value: i8) -> Self {
141 self.transaction_version = value;
142 self
143 }
144 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
145 let producer_id;
146 let producer_epoch;
147 let transaction_result;
148 let topics;
149 let coordinator_epoch;
150 let mut transaction_version = 0i8;
151 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
152 producer_id = read_i64(buf)?;
153 producer_epoch = read_i16(buf)?;
154 transaction_result = read_bool(buf)?;
155 topics = {
156 let len = read_compact_array_length(buf)?;
157 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
158 for _ in 0..len {
159 arr.push(WritableTxnMarkerTopic::read(buf, version)?);
160 }
161 arr
162 };
163 coordinator_epoch = read_i32(buf)?;
164 if version >= 2 {
165 transaction_version = read_i8(buf)?;
166 }
167 let tagged_fields = read_tagged_fields(buf)?;
168 for field in &tagged_fields {
169 match field.tag {
170 _ => {
171 _unknown_tagged_fields.push(field.clone());
172 },
173 }
174 }
175 Ok(Self {
176 producer_id,
177 producer_epoch,
178 transaction_result,
179 topics,
180 coordinator_epoch,
181 transaction_version,
182 _unknown_tagged_fields,
183 })
184 }
185 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
186 write_i64(buf, self.producer_id);
187 write_i16(buf, self.producer_epoch);
188 write_bool(buf, self.transaction_result);
189 write_compact_array_length(buf, self.topics.len() as i32);
190 for el in &self.topics {
191 el.write(buf, version)?;
192 }
193 write_i32(buf, self.coordinator_epoch);
194 if version >= 2 {
195 write_i8(buf, self.transaction_version);
196 } else if self.transaction_version != 0i8 {
197 return Err(UnsupportedFieldVersion::new(27, "transaction_version", version).into());
198 }
199 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
200 all_tags.sort_by_key(|f| f.tag);
201 write_tagged_fields(buf, &all_tags)?;
202 Ok(())
203 }
204 pub fn encoded_len(&self, version: i16) -> Result<usize> {
205 let mut len: usize = 0;
206 len += 8;
207 len += 2;
208 len += 1;
209 len += compact_array_length_len(self.topics.len() as i32);
210 for el in &self.topics {
211 len += el.encoded_len(version)?;
212 }
213 len += 4;
214 if version >= 2 {
215 len += 1;
216 } else if self.transaction_version != 0i8 {
217 return Err(UnsupportedFieldVersion::new(27, "transaction_version", version).into());
218 }
219 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
220 all_tags.sort_by_key(|f| f.tag);
221 len += tagged_fields_len(&all_tags)?;
222 Ok(len)
223 }
224}
225#[derive(Debug, Clone, PartialEq)]
226pub struct WritableTxnMarkerTopic {
227 pub name: KafkaString,
229 pub partition_indexes: Vec<i32>,
231 pub _unknown_tagged_fields: Vec<RawTaggedField>,
232}
233impl Default for WritableTxnMarkerTopic {
234 fn default() -> Self {
235 Self {
236 name: KafkaString::default(),
237 partition_indexes: Vec::new(),
238 _unknown_tagged_fields: Vec::new(),
239 }
240 }
241}
242impl WritableTxnMarkerTopic {
243 pub fn with_name(mut self, value: KafkaString) -> Self {
244 self.name = value;
245 self
246 }
247 pub fn with_partition_indexes(mut self, value: Vec<i32>) -> Self {
248 self.partition_indexes = value;
249 self
250 }
251 pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
252 let name;
253 let partition_indexes;
254 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
255 name = read_compact_string(buf)?;
256 partition_indexes = {
257 let len = read_compact_array_length(buf)?;
258 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
259 for _ in 0..len {
260 arr.push(read_i32(buf)?);
261 }
262 arr
263 };
264 let tagged_fields = read_tagged_fields(buf)?;
265 for field in &tagged_fields {
266 match field.tag {
267 _ => {
268 _unknown_tagged_fields.push(field.clone());
269 },
270 }
271 }
272 Ok(Self {
273 name,
274 partition_indexes,
275 _unknown_tagged_fields,
276 })
277 }
278 pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
279 write_compact_string(buf, &self.name)?;
280 write_compact_array_length(buf, self.partition_indexes.len() as i32);
281 for el in &self.partition_indexes {
282 write_i32(buf, *el);
283 }
284 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
285 all_tags.sort_by_key(|f| f.tag);
286 write_tagged_fields(buf, &all_tags)?;
287 Ok(())
288 }
289 pub fn encoded_len(&self, _version: i16) -> Result<usize> {
290 let mut len: usize = 0;
291 len += compact_string_len(&self.name)?;
292 len += compact_array_length_len(self.partition_indexes.len() as i32);
293 len += self.partition_indexes.len() * 4usize;
294 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
295 all_tags.sort_by_key(|f| f.tag);
296 len += tagged_fields_len(&all_tags)?;
297 Ok(len)
298 }
299}