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