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