krabka_protocol/opt/rustwide/workdir/generated/
WriteShareGroupStateRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 fixed::{get_i8, get_i16, get_i32, get_i64, put_i8, put_i16, put_i32, put_i64},
9 string_bytes::{
10 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
11 put_string, string_len,
12 },
13 },
14 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
15};
16pub const API_KEY: i16 = 85;
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 1;
19pub const LATEST_STABLE_VERSION: i16 = 1;
20pub const FLEXIBLE_MIN: i16 = 0;
21#[inline]
22#[must_use]
23pub fn is_flexible(version: i16) -> bool {
24 version >= FLEXIBLE_MIN
25}
26#[derive(Debug, Clone, PartialEq, Eq, Default)]
27pub struct WriteShareGroupStateRequest {
28 pub group_id: String,
29 pub topics: Vec<WriteStateData>,
30 pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl Encode for WriteShareGroupStateRequest {
33 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
34 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
35 return Err(ProtocolError::UnsupportedVersion {
36 api_key: API_KEY,
37 version,
38 });
39 }
40 let flex = is_flexible(version);
41 if version >= 0 {
42 if flex {
43 let () = put_compact_string(buf, &self.group_id);
44 } else {
45 let () = put_string(buf, &self.group_id);
46 }
47 }
48 if version >= 0 {
49 {
50 crate::primitives::array::put_array_len(buf, (self.topics).len(), flex);
51 for it in &self.topics {
52 it.encode(buf, version)?;
53 }
54 };
55 }
56 if flex {
57 let tagged = WriteTaggedFields::new();
58 tagged.write(buf, &self.unknown_tagged_fields);
59 }
60 Ok(())
61 }
62 fn encoded_len(&self, version: i16) -> usize {
63 let flex = is_flexible(version);
64 let mut n: usize = 0;
65 if version >= 0 {
66 n += if flex {
67 compact_string_len(&self.group_id)
68 } else {
69 string_len(&self.group_id)
70 };
71 }
72 if version >= 0 {
73 n += {
74 let prefix =
75 crate::primitives::array::array_len_prefix_len((self.topics).len(), flex);
76 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
77 prefix + body
78 };
79 }
80 if flex {
81 let known_pairs: Vec<(u32, usize)> = Vec::new();
82 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
83 }
84 n
85 }
86}
87impl Decode<'_> for WriteShareGroupStateRequest {
88 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
89 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
90 return Err(ProtocolError::UnsupportedVersion {
91 api_key: API_KEY,
92 version,
93 });
94 }
95 let flex = is_flexible(version);
96 let mut out = Self::default();
97 if version >= 0 {
98 out.group_id = if flex {
99 get_compact_string_owned(buf)?
100 } else {
101 get_string_owned(buf)?
102 };
103 }
104 if version >= 0 {
105 out.topics = {
106 let n = crate::primitives::array::get_array_len(buf, flex)?;
107 let mut v = Vec::with_capacity(n);
108 for _ in 0..n {
109 v.push(WriteStateData::decode(buf, version)?);
110 }
111 v
112 };
113 }
114 if flex {
115 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
116 }
117 Ok(out)
118 }
119}
120#[cfg(test)]
121impl WriteShareGroupStateRequest {
122 #[must_use]
123 pub fn populated(version: i16) -> Self {
124 let mut m = Self::default();
125 if version >= 0 {
126 m.group_id = "x".to_string();
127 }
128 if version >= 0 {
129 m.topics = vec![WriteStateData::populated(version)];
130 }
131 m
132 }
133}
134#[derive(Debug, Clone, PartialEq, Eq, Default)]
135pub struct WriteStateData {
136 pub topic_id: crate::primitives::uuid::Uuid,
137 pub partitions: Vec<PartitionData>,
138 pub unknown_tagged_fields: UnknownTaggedFields,
139}
140impl Encode for WriteStateData {
141 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
142 let flex = version >= 0;
143 if version >= 0 {
144 crate::primitives::uuid::put_uuid(buf, self.topic_id);
145 }
146 if version >= 0 {
147 {
148 crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex);
149 for it in &self.partitions {
150 it.encode(buf, version)?;
151 }
152 };
153 }
154 if flex {
155 let tagged = WriteTaggedFields::new();
156 tagged.write(buf, &self.unknown_tagged_fields);
157 }
158 Ok(())
159 }
160 fn encoded_len(&self, version: i16) -> usize {
161 let flex = version >= 0;
162 let mut n: usize = 0;
163 if version >= 0 {
164 n += 16;
165 }
166 if version >= 0 {
167 n += {
168 let prefix =
169 crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex);
170 let body: usize = (self.partitions)
171 .iter()
172 .map(|it| it.encoded_len(version))
173 .sum();
174 prefix + body
175 };
176 }
177 if flex {
178 let known_pairs: Vec<(u32, usize)> = Vec::new();
179 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
180 }
181 n
182 }
183}
184impl Decode<'_> for WriteStateData {
185 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
186 let flex = version >= 0;
187 let mut out = Self::default();
188 if version >= 0 {
189 out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
190 }
191 if version >= 0 {
192 out.partitions = {
193 let n = crate::primitives::array::get_array_len(buf, flex)?;
194 let mut v = Vec::with_capacity(n);
195 for _ in 0..n {
196 v.push(PartitionData::decode(buf, version)?);
197 }
198 v
199 };
200 }
201 if flex {
202 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
203 }
204 Ok(out)
205 }
206}
207#[cfg(test)]
208impl WriteStateData {
209 #[must_use]
210 pub fn populated(version: i16) -> Self {
211 let mut m = Self::default();
212 if version >= 0 {
213 m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
214 }
215 if version >= 0 {
216 m.partitions = vec![PartitionData::populated(version)];
217 }
218 m
219 }
220}
221#[derive(Debug, Clone, PartialEq, Eq)]
222pub struct PartitionData {
223 pub partition: i32,
224 pub state_epoch: i32,
225 pub leader_epoch: i32,
226 pub start_offset: i64,
227 pub delivery_complete_count: i32,
228 pub state_batches: Vec<StateBatch>,
229 pub unknown_tagged_fields: UnknownTaggedFields,
230}
231impl Default for PartitionData {
232 fn default() -> Self {
233 Self {
234 partition: 0i32,
235 state_epoch: 0i32,
236 leader_epoch: 0i32,
237 start_offset: 0i64,
238 delivery_complete_count: -1i32,
239 state_batches: Vec::new(),
240 unknown_tagged_fields: UnknownTaggedFields::default(),
241 }
242 }
243}
244impl Encode for PartitionData {
245 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
246 let flex = version >= 0;
247 if version >= 0 {
248 put_i32(buf, self.partition);
249 }
250 if version >= 0 {
251 put_i32(buf, self.state_epoch);
252 }
253 if version >= 0 {
254 put_i32(buf, self.leader_epoch);
255 }
256 if version >= 0 {
257 put_i64(buf, self.start_offset);
258 }
259 if version >= 1 {
260 put_i32(buf, self.delivery_complete_count);
261 }
262 if version >= 0 {
263 {
264 crate::primitives::array::put_array_len(buf, (self.state_batches).len(), flex);
265 for it in &self.state_batches {
266 it.encode(buf, version)?;
267 }
268 };
269 }
270 if flex {
271 let tagged = WriteTaggedFields::new();
272 tagged.write(buf, &self.unknown_tagged_fields);
273 }
274 Ok(())
275 }
276 fn encoded_len(&self, version: i16) -> usize {
277 let flex = version >= 0;
278 let mut n: usize = 0;
279 if version >= 0 {
280 n += 4;
281 }
282 if version >= 0 {
283 n += 4;
284 }
285 if version >= 0 {
286 n += 4;
287 }
288 if version >= 0 {
289 n += 8;
290 }
291 if version >= 1 {
292 n += 4;
293 }
294 if version >= 0 {
295 n += {
296 let prefix = crate::primitives::array::array_len_prefix_len(
297 (self.state_batches).len(),
298 flex,
299 );
300 let body: usize = (self.state_batches)
301 .iter()
302 .map(|it| it.encoded_len(version))
303 .sum();
304 prefix + body
305 };
306 }
307 if flex {
308 let known_pairs: Vec<(u32, usize)> = Vec::new();
309 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
310 }
311 n
312 }
313}
314impl Decode<'_> for PartitionData {
315 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
316 let flex = version >= 0;
317 let mut out = Self::default();
318 if version >= 0 {
319 out.partition = get_i32(buf)?;
320 }
321 if version >= 0 {
322 out.state_epoch = get_i32(buf)?;
323 }
324 if version >= 0 {
325 out.leader_epoch = get_i32(buf)?;
326 }
327 if version >= 0 {
328 out.start_offset = get_i64(buf)?;
329 }
330 if version >= 1 {
331 out.delivery_complete_count = get_i32(buf)?;
332 }
333 if version >= 0 {
334 out.state_batches = {
335 let n = crate::primitives::array::get_array_len(buf, flex)?;
336 let mut v = Vec::with_capacity(n);
337 for _ in 0..n {
338 v.push(StateBatch::decode(buf, version)?);
339 }
340 v
341 };
342 }
343 if flex {
344 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
345 }
346 Ok(out)
347 }
348}
349#[cfg(test)]
350impl PartitionData {
351 #[must_use]
352 pub fn populated(version: i16) -> Self {
353 let mut m = Self::default();
354 if version >= 0 {
355 m.partition = 1i32;
356 }
357 if version >= 0 {
358 m.state_epoch = 1i32;
359 }
360 if version >= 0 {
361 m.leader_epoch = 1i32;
362 }
363 if version >= 0 {
364 m.start_offset = 1i64;
365 }
366 if version >= 1 {
367 m.delivery_complete_count = 1i32;
368 }
369 if version >= 0 {
370 m.state_batches = vec![StateBatch::populated(version)];
371 }
372 m
373 }
374}
375#[derive(Debug, Clone, PartialEq, Eq, Default)]
376pub struct StateBatch {
377 pub first_offset: i64,
378 pub last_offset: i64,
379 pub delivery_state: i8,
380 pub delivery_count: i16,
381 pub unknown_tagged_fields: UnknownTaggedFields,
382}
383impl Encode for StateBatch {
384 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
385 let flex = version >= 0;
386 if version >= 0 {
387 put_i64(buf, self.first_offset);
388 }
389 if version >= 0 {
390 put_i64(buf, self.last_offset);
391 }
392 if version >= 0 {
393 put_i8(buf, self.delivery_state);
394 }
395 if version >= 0 {
396 put_i16(buf, self.delivery_count);
397 }
398 if flex {
399 let tagged = WriteTaggedFields::new();
400 tagged.write(buf, &self.unknown_tagged_fields);
401 }
402 Ok(())
403 }
404 fn encoded_len(&self, version: i16) -> usize {
405 let flex = version >= 0;
406 let mut n: usize = 0;
407 if version >= 0 {
408 n += 8;
409 }
410 if version >= 0 {
411 n += 8;
412 }
413 if version >= 0 {
414 n += 1;
415 }
416 if version >= 0 {
417 n += 2;
418 }
419 if flex {
420 let known_pairs: Vec<(u32, usize)> = Vec::new();
421 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
422 }
423 n
424 }
425}
426impl Decode<'_> for StateBatch {
427 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
428 let flex = version >= 0;
429 let mut out = Self::default();
430 if version >= 0 {
431 out.first_offset = get_i64(buf)?;
432 }
433 if version >= 0 {
434 out.last_offset = get_i64(buf)?;
435 }
436 if version >= 0 {
437 out.delivery_state = get_i8(buf)?;
438 }
439 if version >= 0 {
440 out.delivery_count = get_i16(buf)?;
441 }
442 if flex {
443 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
444 }
445 Ok(out)
446 }
447}
448#[cfg(test)]
449impl StateBatch {
450 #[must_use]
451 pub fn populated(version: i16) -> Self {
452 let mut m = Self::default();
453 if version >= 0 {
454 m.first_offset = 1i64;
455 }
456 if version >= 0 {
457 m.last_offset = 1i64;
458 }
459 if version >= 0 {
460 m.delivery_state = 1i8;
461 }
462 if version >= 0 {
463 m.delivery_count = 1i16;
464 }
465 m
466 }
467}
468#[must_use]
471#[allow(unused_comparisons)]
472pub fn default_json(_version: i16) -> ::serde_json::Value {
473 let mut obj = ::serde_json::Map::new();
474 obj.insert(
475 "groupId".to_string(),
476 ::serde_json::Value::String(String::new()),
477 );
478 obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
479 ::serde_json::Value::Object(obj)
480}
481impl crate::ProtocolRequest for WriteShareGroupStateRequest {
482 const API_KEY: i16 = API_KEY;
483 const MIN_VERSION: i16 = MIN_VERSION;
484 const MAX_VERSION: i16 = MAX_VERSION;
485 const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
486 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
487 type Response = super::write_share_group_state_response::WriteShareGroupStateResponse;
488}