krabka_protocol/opt/rustwide/workdir/generated/
OffsetCommitRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 array::{array_len_prefix_len, get_array_len, put_array_len},
9 fixed::{get_i32, get_i64, put_i32, put_i64},
10 string_bytes::{
11 compact_nullable_string_len, compact_string_len, get_compact_nullable_string_owned,
12 get_compact_string_owned, get_nullable_string_owned, get_string_owned,
13 nullable_string_len, put_compact_nullable_string, put_compact_string,
14 put_nullable_string, put_string, string_len,
15 },
16 uuid::{Uuid, get_uuid, put_uuid},
17 },
18 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
19};
20pub const API_KEY: i16 = 8;
21pub const MIN_VERSION: i16 = 2;
22pub const MAX_VERSION: i16 = 10;
23pub const LATEST_STABLE_VERSION: i16 = 10;
24pub const FLEXIBLE_MIN: i16 = 8;
25#[inline]
26#[must_use]
27pub fn is_flexible(version: i16) -> bool {
28 version >= FLEXIBLE_MIN
29}
30#[derive(Debug, Clone, PartialEq, Eq)]
31pub struct OffsetCommitRequest {
32 pub group_id: String,
33 pub generation_id_or_member_epoch: i32,
34 pub member_id: String,
35 pub group_instance_id: Option<String>,
36 pub retention_time_ms: i64,
37 pub topics: Vec<OffsetCommitRequestTopic>,
38 pub unknown_tagged_fields: UnknownTaggedFields,
39}
40impl Default for OffsetCommitRequest {
41 fn default() -> Self {
42 Self {
43 group_id: String::new(),
44 generation_id_or_member_epoch: -1i32,
45 member_id: String::new(),
46 group_instance_id: None,
47 retention_time_ms: -1i64,
48 topics: Vec::new(),
49 unknown_tagged_fields: UnknownTaggedFields::default(),
50 }
51 }
52}
53impl Encode for OffsetCommitRequest {
54 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
55 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
56 return Err(ProtocolError::UnsupportedVersion {
57 api_key: API_KEY,
58 version,
59 });
60 }
61 let flex = is_flexible(version);
62 if version >= 0 {
63 if flex {
64 put_compact_string(buf, &self.group_id)?;
65 } else {
66 put_string(buf, &self.group_id)?;
67 }
68 }
69 if version >= 1 {
70 put_i32(buf, self.generation_id_or_member_epoch);
71 }
72 if version >= 1 {
73 if flex {
74 put_compact_string(buf, &self.member_id)?;
75 } else {
76 put_string(buf, &self.member_id)?;
77 }
78 }
79 if version >= 7 {
80 if flex {
81 put_compact_nullable_string(buf, self.group_instance_id.as_deref())?;
82 } else {
83 put_nullable_string(buf, self.group_instance_id.as_deref())?;
84 }
85 }
86 if (2..=4).contains(&version) {
87 put_i64(buf, self.retention_time_ms);
88 }
89 if version >= 0 {
90 {
91 put_array_len(buf, (self.topics).len(), flex)?;
92 for it in &self.topics {
93 it.encode(buf, version)?;
94 }
95 }
96 }
97 if flex {
98 let tagged = WriteTaggedFields::new();
99 tagged.write(buf, &self.unknown_tagged_fields)?;
100 }
101 Ok(())
102 }
103 fn encoded_len(&self, version: i16) -> usize {
104 let flex = is_flexible(version);
105 let mut n: usize = 0;
106 if version >= 0 {
107 n += if flex {
108 compact_string_len(&self.group_id)
109 } else {
110 string_len(&self.group_id)
111 };
112 }
113 if version >= 1 {
114 n += 4;
115 }
116 if version >= 1 {
117 n += if flex {
118 compact_string_len(&self.member_id)
119 } else {
120 string_len(&self.member_id)
121 };
122 }
123 if version >= 7 {
124 n += if flex {
125 compact_nullable_string_len(self.group_instance_id.as_deref())
126 } else {
127 nullable_string_len(self.group_instance_id.as_deref())
128 };
129 }
130 if (2..=4).contains(&version) {
131 n += 8;
132 }
133 if version >= 0 {
134 n += {
135 let prefix = array_len_prefix_len((self.topics).len(), flex);
136 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
137 prefix + body
138 };
139 }
140 if flex {
141 let known_pairs: Vec<(u32, usize)> = Vec::new();
142 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
143 }
144 n
145 }
146}
147impl Decode<'_> for OffsetCommitRequest {
148 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
149 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
150 return Err(ProtocolError::UnsupportedVersion {
151 api_key: API_KEY,
152 version,
153 });
154 }
155 let flex = is_flexible(version);
156 let mut out = Self::default();
157 if version >= 0 {
158 out.group_id = if flex {
159 get_compact_string_owned(buf)?
160 } else {
161 get_string_owned(buf)?
162 };
163 }
164 if version >= 1 {
165 out.generation_id_or_member_epoch = get_i32(buf)?;
166 }
167 if version >= 1 {
168 out.member_id = if flex {
169 get_compact_string_owned(buf)?
170 } else {
171 get_string_owned(buf)?
172 };
173 }
174 if version >= 7 {
175 out.group_instance_id = if flex {
176 get_compact_nullable_string_owned(buf)?
177 } else {
178 get_nullable_string_owned(buf)?
179 };
180 }
181 if (2..=4).contains(&version) {
182 out.retention_time_ms = get_i64(buf)?;
183 }
184 if version >= 0 {
185 out.topics = {
186 let n = get_array_len(buf, flex)?;
187 let mut v = Vec::with_capacity(n);
188 for _ in 0..n {
189 v.push(OffsetCommitRequestTopic::decode(buf, version)?);
190 }
191 v
192 };
193 }
194 if flex {
195 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
196 }
197 Ok(out)
198 }
199}
200#[cfg(test)]
201impl OffsetCommitRequest {
202 #[must_use]
203 pub fn populated(version: i16) -> Self {
204 let mut m = Self::default();
205 if version >= 0 {
206 m.group_id = "x".to_owned();
207 }
208 if version >= 1 {
209 m.generation_id_or_member_epoch = 1i32;
210 }
211 if version >= 1 {
212 m.member_id = "x".to_owned();
213 }
214 if version >= 7 {
215 m.group_instance_id = Some("x".to_owned());
216 }
217 if (2..=4).contains(&version) {
218 m.retention_time_ms = 1i64;
219 }
220 if version >= 0 {
221 m.topics = vec![OffsetCommitRequestTopic::populated(version)];
222 }
223 m
224 }
225}
226#[derive(Debug, Clone, PartialEq, Eq, Default)]
227pub struct OffsetCommitRequestTopic {
228 pub name: String,
229 pub topic_id: Uuid,
230 pub partitions: Vec<OffsetCommitRequestPartition>,
231 pub unknown_tagged_fields: UnknownTaggedFields,
232}
233impl Encode for OffsetCommitRequestTopic {
234 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
235 let flex = version >= 8;
236 if (0..=9).contains(&version) {
237 if flex {
238 put_compact_string(buf, &self.name)?;
239 } else {
240 put_string(buf, &self.name)?;
241 }
242 }
243 if version >= 10 {
244 put_uuid(buf, self.topic_id);
245 }
246 if version >= 0 {
247 {
248 put_array_len(buf, (self.partitions).len(), flex)?;
249 for it in &self.partitions {
250 it.encode(buf, version)?;
251 }
252 }
253 }
254 if flex {
255 let tagged = WriteTaggedFields::new();
256 tagged.write(buf, &self.unknown_tagged_fields)?;
257 }
258 Ok(())
259 }
260 fn encoded_len(&self, version: i16) -> usize {
261 let flex = version >= 8;
262 let mut n: usize = 0;
263 if (0..=9).contains(&version) {
264 n += if flex {
265 compact_string_len(&self.name)
266 } else {
267 string_len(&self.name)
268 };
269 }
270 if version >= 10 {
271 n += 16;
272 }
273 if version >= 0 {
274 n += {
275 let prefix = 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 = get_uuid(buf)?;
303 }
304 if version >= 0 {
305 out.partitions = {
306 let n = 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_owned();
327 }
328 if version >= 10 {
329 m.topic_id = 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 put_compact_nullable_string(buf, self.committed_metadata.as_deref())?;
371 } else {
372 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_owned());
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_owned(),
461 ::serde_json::Value::String(String::new()),
462 );
463 if version >= 1 {
464 obj.insert(
465 "generationIdOrMemberEpoch".to_owned(),
466 ::serde_json::json!(-1),
467 );
468 }
469 if version >= 1 {
470 obj.insert(
471 "memberId".to_owned(),
472 ::serde_json::Value::String(String::new()),
473 );
474 }
475 if version >= 7 {
476 obj.insert("groupInstanceId".to_owned(), ::serde_json::Value::Null);
477 }
478 if (2..=4).contains(&version) {
479 obj.insert("retentionTimeMs".to_owned(), ::serde_json::json!(-1));
480 }
481 obj.insert("topics".to_owned(), ::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}