Skip to main content

kacrab_protocol/generated/
add_offsets_to_txn_request.rs

1//! Generated from AddOffsetsToTxnRequest.json - DO NOT EDIT
2#![allow(
3    missing_docs,
4    clippy::all,
5    clippy::pedantic,
6    clippy::nursery,
7    clippy::arithmetic_side_effects,
8    reason = "Generated protocol modules mirror Kafka's schema shape and intentionally trade \
9              hand-written lint style for reproducible wire-code output."
10)]
11use bytes::{Bytes, BytesMut};
12
13use crate::*;
14
15#[derive(Debug, Clone, PartialEq)]
16pub struct AddOffsetsToTxnRequestData {
17    /// The transactional id corresponding to the transaction.
18    pub transactional_id: KafkaString,
19    /// Current producer id in use by the transactional id.
20    pub producer_id: i64,
21    /// Current epoch associated with the producer id.
22    pub producer_epoch: i16,
23    /// The unique group identifier.
24    pub group_id: KafkaString,
25    pub _unknown_tagged_fields: Vec<RawTaggedField>,
26}
27impl Default for AddOffsetsToTxnRequestData {
28    fn default() -> Self {
29        Self {
30            transactional_id: KafkaString::default(),
31            producer_id: 0_i64,
32            producer_epoch: 0_i16,
33            group_id: KafkaString::default(),
34            _unknown_tagged_fields: Vec::new(),
35        }
36    }
37}
38impl AddOffsetsToTxnRequestData {
39    pub fn with_transactional_id(mut self, value: KafkaString) -> Self {
40        self.transactional_id = value;
41        self
42    }
43    pub fn with_producer_id(mut self, value: i64) -> Self {
44        self.producer_id = value;
45        self
46    }
47    pub fn with_producer_epoch(mut self, value: i16) -> Self {
48        self.producer_epoch = value;
49        self
50    }
51    pub fn with_group_id(mut self, value: KafkaString) -> Self {
52        self.group_id = value;
53        self
54    }
55    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
56        if version < 0 || version > 4 {
57            return Err(UnsupportedVersion::new(25, version).into());
58        }
59        let transactional_id;
60        let producer_id;
61        let producer_epoch;
62        let group_id;
63        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
64        if version >= 3 {
65            transactional_id = read_compact_string(buf)?;
66        } else {
67            transactional_id = read_string(buf)?;
68        }
69        producer_id = read_i64(buf)?;
70        producer_epoch = read_i16(buf)?;
71        if version >= 3 {
72            group_id = read_compact_string(buf)?;
73        } else {
74            group_id = read_string(buf)?;
75        }
76        if version >= 3 {
77            let tagged_fields = read_tagged_fields(buf)?;
78            for field in &tagged_fields {
79                match field.tag {
80                    _ => {
81                        _unknown_tagged_fields.push(field.clone());
82                    },
83                }
84            }
85        }
86        Ok(Self {
87            transactional_id,
88            producer_id,
89            producer_epoch,
90            group_id,
91            _unknown_tagged_fields,
92        })
93    }
94    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
95        if version < 0 || version > 4 {
96            return Err(UnsupportedVersion::new(25, version).into());
97        }
98        if version >= 3 {
99            write_compact_string(buf, &self.transactional_id)?;
100        } else {
101            write_string(buf, &self.transactional_id)?;
102        }
103        write_i64(buf, self.producer_id);
104        write_i16(buf, self.producer_epoch);
105        if version >= 3 {
106            write_compact_string(buf, &self.group_id)?;
107        } else {
108            write_string(buf, &self.group_id)?;
109        }
110        if version >= 3 {
111            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
112            all_tags.sort_by_key(|f| f.tag);
113            write_tagged_fields(buf, &all_tags)?;
114        }
115        Ok(())
116    }
117    pub fn encoded_len(&self, version: i16) -> Result<usize> {
118        if version < 0 || version > 4 {
119            return Err(UnsupportedVersion::new(25, version).into());
120        }
121        let mut len: usize = 0;
122        if version >= 3 {
123            len += compact_string_len(&self.transactional_id)?;
124        } else {
125            len += string_len(&self.transactional_id)?;
126        }
127        len += 8;
128        len += 2;
129        if version >= 3 {
130            len += compact_string_len(&self.group_id)?;
131        } else {
132            len += string_len(&self.group_id)?;
133        }
134        if version >= 3 {
135            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
136            all_tags.sort_by_key(|f| f.tag);
137            len += tagged_fields_len(&all_tags)?;
138        }
139        Ok(len)
140    }
141}