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