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