Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
TxnOffsetCommitRequest.owned.rs

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