kacrab_protocol/generated/
write_share_group_state_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 WriteShareGroupStateRequestData {
17 pub group_id: KafkaString,
19 pub topics: Vec<WriteStateData>,
21 pub _unknown_tagged_fields: Vec<RawTaggedField>,
22}
23impl Default for WriteShareGroupStateRequestData {
24 fn default() -> Self {
25 Self {
26 group_id: KafkaString::default(),
27 topics: Vec::new(),
28 _unknown_tagged_fields: Vec::new(),
29 }
30 }
31}
32impl WriteShareGroupStateRequestData {
33 pub fn with_group_id(mut self, value: KafkaString) -> Self {
34 self.group_id = value;
35 self
36 }
37 pub fn with_topics(mut self, value: Vec<WriteStateData>) -> Self {
38 self.topics = value;
39 self
40 }
41 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
42 if version < 0 || version > 1 {
43 return Err(UnsupportedVersion::new(85, version).into());
44 }
45 let group_id;
46 let topics;
47 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
48 group_id = read_compact_string(buf)?;
49 topics = {
50 let len = read_compact_array_length(buf)?;
51 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
52 for _ in 0..len {
53 arr.push(WriteStateData::read(buf, version)?);
54 }
55 arr
56 };
57 let tagged_fields = read_tagged_fields(buf)?;
58 for field in &tagged_fields {
59 match field.tag {
60 _ => {
61 _unknown_tagged_fields.push(field.clone());
62 },
63 }
64 }
65 Ok(Self {
66 group_id,
67 topics,
68 _unknown_tagged_fields,
69 })
70 }
71 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
72 if version < 0 || version > 1 {
73 return Err(UnsupportedVersion::new(85, version).into());
74 }
75 write_compact_string(buf, &self.group_id)?;
76 write_compact_array_length(buf, self.topics.len() as i32);
77 for el in &self.topics {
78 el.write(buf, version)?;
79 }
80 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
81 all_tags.sort_by_key(|f| f.tag);
82 write_tagged_fields(buf, &all_tags)?;
83 Ok(())
84 }
85 pub fn encoded_len(&self, version: i16) -> Result<usize> {
86 if version < 0 || version > 1 {
87 return Err(UnsupportedVersion::new(85, version).into());
88 }
89 let mut len: usize = 0;
90 len += compact_string_len(&self.group_id)?;
91 len += compact_array_length_len(self.topics.len() as i32);
92 for el in &self.topics {
93 len += el.encoded_len(version)?;
94 }
95 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
96 all_tags.sort_by_key(|f| f.tag);
97 len += tagged_fields_len(&all_tags)?;
98 Ok(len)
99 }
100}
101#[derive(Debug, Clone, PartialEq)]
102pub struct WriteStateData {
103 pub topic_id: KafkaUuid,
105 pub partitions: Vec<PartitionData>,
107 pub _unknown_tagged_fields: Vec<RawTaggedField>,
108}
109impl Default for WriteStateData {
110 fn default() -> Self {
111 Self {
112 topic_id: KafkaUuid::ZERO,
113 partitions: Vec::new(),
114 _unknown_tagged_fields: Vec::new(),
115 }
116 }
117}
118impl WriteStateData {
119 pub fn with_topic_id(mut self, value: KafkaUuid) -> Self {
120 self.topic_id = value;
121 self
122 }
123 pub fn with_partitions(mut self, value: Vec<PartitionData>) -> Self {
124 self.partitions = value;
125 self
126 }
127 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
128 let topic_id;
129 let partitions;
130 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
131 topic_id = read_uuid(buf)?;
132 partitions = {
133 let len = read_compact_array_length(buf)?;
134 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
135 for _ in 0..len {
136 arr.push(PartitionData::read(buf, version)?);
137 }
138 arr
139 };
140 let tagged_fields = read_tagged_fields(buf)?;
141 for field in &tagged_fields {
142 match field.tag {
143 _ => {
144 _unknown_tagged_fields.push(field.clone());
145 },
146 }
147 }
148 Ok(Self {
149 topic_id,
150 partitions,
151 _unknown_tagged_fields,
152 })
153 }
154 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
155 write_uuid(buf, &self.topic_id);
156 write_compact_array_length(buf, self.partitions.len() as i32);
157 for el in &self.partitions {
158 el.write(buf, version)?;
159 }
160 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
161 all_tags.sort_by_key(|f| f.tag);
162 write_tagged_fields(buf, &all_tags)?;
163 Ok(())
164 }
165 pub fn encoded_len(&self, version: i16) -> Result<usize> {
166 let mut len: usize = 0;
167 len += 16;
168 len += compact_array_length_len(self.partitions.len() as i32);
169 for el in &self.partitions {
170 len += el.encoded_len(version)?;
171 }
172 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
173 all_tags.sort_by_key(|f| f.tag);
174 len += tagged_fields_len(&all_tags)?;
175 Ok(len)
176 }
177}
178#[derive(Debug, Clone, PartialEq)]
179pub struct PartitionData {
180 pub partition: i32,
182 pub state_epoch: i32,
184 pub leader_epoch: i32,
186 pub start_offset: i64,
188 pub delivery_complete_count: i32,
191 pub state_batches: Vec<StateBatch>,
193 pub _unknown_tagged_fields: Vec<RawTaggedField>,
194}
195impl Default for PartitionData {
196 fn default() -> Self {
197 Self {
198 partition: 0_i32,
199 state_epoch: 0_i32,
200 leader_epoch: 0_i32,
201 start_offset: 0_i64,
202 delivery_complete_count: -1i32,
203 state_batches: Vec::new(),
204 _unknown_tagged_fields: Vec::new(),
205 }
206 }
207}
208impl PartitionData {
209 pub fn with_partition(mut self, value: i32) -> Self {
210 self.partition = value;
211 self
212 }
213 pub fn with_state_epoch(mut self, value: i32) -> Self {
214 self.state_epoch = value;
215 self
216 }
217 pub fn with_leader_epoch(mut self, value: i32) -> Self {
218 self.leader_epoch = value;
219 self
220 }
221 pub fn with_start_offset(mut self, value: i64) -> Self {
222 self.start_offset = value;
223 self
224 }
225 pub fn with_delivery_complete_count(mut self, value: i32) -> Self {
226 self.delivery_complete_count = value;
227 self
228 }
229 pub fn with_state_batches(mut self, value: Vec<StateBatch>) -> Self {
230 self.state_batches = value;
231 self
232 }
233 pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
234 let partition;
235 let state_epoch;
236 let leader_epoch;
237 let start_offset;
238 let mut delivery_complete_count = -1i32;
239 let state_batches;
240 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
241 partition = read_i32(buf)?;
242 state_epoch = read_i32(buf)?;
243 leader_epoch = read_i32(buf)?;
244 start_offset = read_i64(buf)?;
245 if version >= 1 {
246 delivery_complete_count = read_i32(buf)?;
247 }
248 state_batches = {
249 let len = read_compact_array_length(buf)?;
250 let mut arr = Vec::with_capacity(array_read_capacity(len, (buf).len()));
251 for _ in 0..len {
252 arr.push(StateBatch::read(buf, version)?);
253 }
254 arr
255 };
256 let tagged_fields = read_tagged_fields(buf)?;
257 for field in &tagged_fields {
258 match field.tag {
259 _ => {
260 _unknown_tagged_fields.push(field.clone());
261 },
262 }
263 }
264 Ok(Self {
265 partition,
266 state_epoch,
267 leader_epoch,
268 start_offset,
269 delivery_complete_count,
270 state_batches,
271 _unknown_tagged_fields,
272 })
273 }
274 pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
275 write_i32(buf, self.partition);
276 write_i32(buf, self.state_epoch);
277 write_i32(buf, self.leader_epoch);
278 write_i64(buf, self.start_offset);
279 if version >= 1 {
280 write_i32(buf, self.delivery_complete_count);
281 } else if self.delivery_complete_count != -1i32 {
282 return Err(
283 UnsupportedFieldVersion::new(85, "delivery_complete_count", version).into(),
284 );
285 }
286 write_compact_array_length(buf, self.state_batches.len() as i32);
287 for el in &self.state_batches {
288 el.write(buf, version)?;
289 }
290 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
291 all_tags.sort_by_key(|f| f.tag);
292 write_tagged_fields(buf, &all_tags)?;
293 Ok(())
294 }
295 pub fn encoded_len(&self, version: i16) -> Result<usize> {
296 let mut len: usize = 0;
297 len += 4;
298 len += 4;
299 len += 4;
300 len += 8;
301 if version >= 1 {
302 len += 4;
303 } else if self.delivery_complete_count != -1i32 {
304 return Err(
305 UnsupportedFieldVersion::new(85, "delivery_complete_count", version).into(),
306 );
307 }
308 len += compact_array_length_len(self.state_batches.len() as i32);
309 for el in &self.state_batches {
310 len += el.encoded_len(version)?;
311 }
312 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
313 all_tags.sort_by_key(|f| f.tag);
314 len += tagged_fields_len(&all_tags)?;
315 Ok(len)
316 }
317}
318#[derive(Debug, Clone, PartialEq)]
319pub struct StateBatch {
320 pub first_offset: i64,
322 pub last_offset: i64,
324 pub delivery_state: i8,
326 pub delivery_count: i16,
328 pub _unknown_tagged_fields: Vec<RawTaggedField>,
329}
330impl Default for StateBatch {
331 fn default() -> Self {
332 Self {
333 first_offset: 0_i64,
334 last_offset: 0_i64,
335 delivery_state: 0_i8,
336 delivery_count: 0_i16,
337 _unknown_tagged_fields: Vec::new(),
338 }
339 }
340}
341impl StateBatch {
342 pub fn with_first_offset(mut self, value: i64) -> Self {
343 self.first_offset = value;
344 self
345 }
346 pub fn with_last_offset(mut self, value: i64) -> Self {
347 self.last_offset = value;
348 self
349 }
350 pub fn with_delivery_state(mut self, value: i8) -> Self {
351 self.delivery_state = value;
352 self
353 }
354 pub fn with_delivery_count(mut self, value: i16) -> Self {
355 self.delivery_count = value;
356 self
357 }
358 pub fn read(buf: &mut Bytes, _version: i16) -> Result<Self> {
359 let first_offset;
360 let last_offset;
361 let delivery_state;
362 let delivery_count;
363 let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
364 first_offset = read_i64(buf)?;
365 last_offset = read_i64(buf)?;
366 delivery_state = read_i8(buf)?;
367 delivery_count = read_i16(buf)?;
368 let tagged_fields = read_tagged_fields(buf)?;
369 for field in &tagged_fields {
370 match field.tag {
371 _ => {
372 _unknown_tagged_fields.push(field.clone());
373 },
374 }
375 }
376 Ok(Self {
377 first_offset,
378 last_offset,
379 delivery_state,
380 delivery_count,
381 _unknown_tagged_fields,
382 })
383 }
384 pub fn write(&self, buf: &mut BytesMut, _version: i16) -> Result<()> {
385 write_i64(buf, self.first_offset);
386 write_i64(buf, self.last_offset);
387 write_i8(buf, self.delivery_state);
388 write_i16(buf, self.delivery_count);
389 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
390 all_tags.sort_by_key(|f| f.tag);
391 write_tagged_fields(buf, &all_tags)?;
392 Ok(())
393 }
394 pub fn encoded_len(&self, _version: i16) -> Result<usize> {
395 let mut len: usize = 0;
396 len += 8;
397 len += 8;
398 len += 1;
399 len += 2;
400 let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
401 all_tags.sort_by_key(|f| f.tag);
402 len += tagged_fields_len(&all_tags)?;
403 Ok(len)
404 }
405}