Skip to main content

kacrab_protocol/generated/
init_producer_id_request.rs

1//! Generated from InitProducerIdRequest.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 InitProducerIdRequestData {
17    /// The transactional id, or null if the producer is not transactional.
18    pub transactional_id: Option<KafkaString>,
19    /// The time in ms to wait before aborting idle transactions sent by this producer. This is
20    /// only relevant if a TransactionalId has been defined.
21    pub transaction_timeout_ms: i32,
22    /// The producer id. This is used to disambiguate requests if a transactional id is reused
23    /// following its expiration.
24    pub producer_id: i64,
25    /// The producer's current epoch. This will be checked against the producer epoch on the
26    /// broker, and the request will return an error if they do not match.
27    pub producer_epoch: i16,
28    /// True if the client wants to enable two-phase commit (2PC) protocol for transactions.
29    pub enable2_pc: bool,
30    /// True if the client wants to keep the currently ongoing transaction instead of aborting it.
31    pub keep_prepared_txn: bool,
32    pub _unknown_tagged_fields: Vec<RawTaggedField>,
33}
34impl Default for InitProducerIdRequestData {
35    fn default() -> Self {
36        Self {
37            transactional_id: None,
38            transaction_timeout_ms: 0_i32,
39            producer_id: -1i64,
40            producer_epoch: -1i16,
41            enable2_pc: false,
42            keep_prepared_txn: false,
43            _unknown_tagged_fields: Vec::new(),
44        }
45    }
46}
47impl InitProducerIdRequestData {
48    pub fn with_transactional_id(mut self, value: Option<KafkaString>) -> Self {
49        self.transactional_id = value;
50        self
51    }
52    pub fn with_transaction_timeout_ms(mut self, value: i32) -> Self {
53        self.transaction_timeout_ms = value;
54        self
55    }
56    pub fn with_producer_id(mut self, value: i64) -> Self {
57        self.producer_id = value;
58        self
59    }
60    pub fn with_producer_epoch(mut self, value: i16) -> Self {
61        self.producer_epoch = value;
62        self
63    }
64    pub fn with_enable2_pc(mut self, value: bool) -> Self {
65        self.enable2_pc = value;
66        self
67    }
68    pub fn with_keep_prepared_txn(mut self, value: bool) -> Self {
69        self.keep_prepared_txn = value;
70        self
71    }
72    pub fn read(buf: &mut Bytes, version: i16) -> Result<Self> {
73        if version < 0 || version > 6 {
74            return Err(UnsupportedVersion::new(22, version).into());
75        }
76        let transactional_id;
77        let transaction_timeout_ms;
78        let mut producer_id = -1i64;
79        let mut producer_epoch = -1i16;
80        let mut enable2_pc = false;
81        let mut keep_prepared_txn = false;
82        let mut _unknown_tagged_fields: Vec<RawTaggedField> = Vec::new();
83        if version >= 2 {
84            transactional_id = read_compact_nullable_string(buf)?;
85        } else {
86            transactional_id = read_nullable_string(buf)?;
87        }
88        transaction_timeout_ms = read_i32(buf)?;
89        if version >= 3 {
90            producer_id = read_i64(buf)?;
91        }
92        if version >= 3 {
93            producer_epoch = read_i16(buf)?;
94        }
95        if version >= 6 {
96            enable2_pc = read_bool(buf)?;
97        }
98        if version >= 6 {
99            keep_prepared_txn = read_bool(buf)?;
100        }
101        if version >= 2 {
102            let tagged_fields = read_tagged_fields(buf)?;
103            for field in &tagged_fields {
104                match field.tag {
105                    _ => {
106                        _unknown_tagged_fields.push(field.clone());
107                    },
108                }
109            }
110        }
111        Ok(Self {
112            transactional_id,
113            transaction_timeout_ms,
114            producer_id,
115            producer_epoch,
116            enable2_pc,
117            keep_prepared_txn,
118            _unknown_tagged_fields,
119        })
120    }
121    pub fn write(&self, buf: &mut BytesMut, version: i16) -> Result<()> {
122        if version < 0 || version > 6 {
123            return Err(UnsupportedVersion::new(22, version).into());
124        }
125        if version >= 2 {
126            write_compact_nullable_string(buf, self.transactional_id.as_ref())?;
127        } else {
128            write_nullable_string(buf, self.transactional_id.as_ref())?;
129        }
130        write_i32(buf, self.transaction_timeout_ms);
131        if version >= 3 {
132            write_i64(buf, self.producer_id);
133        } else if self.producer_id != -1i64 {
134            return Err(UnsupportedFieldVersion::new(22, "producer_id", version).into());
135        }
136        if version >= 3 {
137            write_i16(buf, self.producer_epoch);
138        } else if self.producer_epoch != -1i16 {
139            return Err(UnsupportedFieldVersion::new(22, "producer_epoch", version).into());
140        }
141        if version >= 6 {
142            write_bool(buf, self.enable2_pc);
143        } else if self.enable2_pc != false {
144            return Err(UnsupportedFieldVersion::new(22, "enable2_pc", version).into());
145        }
146        if version >= 6 {
147            write_bool(buf, self.keep_prepared_txn);
148        } else if self.keep_prepared_txn != false {
149            return Err(UnsupportedFieldVersion::new(22, "keep_prepared_txn", version).into());
150        }
151        if version >= 2 {
152            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
153            all_tags.sort_by_key(|f| f.tag);
154            write_tagged_fields(buf, &all_tags)?;
155        }
156        Ok(())
157    }
158    pub fn encoded_len(&self, version: i16) -> Result<usize> {
159        if version < 0 || version > 6 {
160            return Err(UnsupportedVersion::new(22, version).into());
161        }
162        let mut len: usize = 0;
163        if version >= 2 {
164            len += compact_nullable_string_len(self.transactional_id.as_ref())?;
165        } else {
166            len += nullable_string_len(self.transactional_id.as_ref())?;
167        }
168        len += 4;
169        if version >= 3 {
170            len += 8;
171        } else if self.producer_id != -1i64 {
172            return Err(UnsupportedFieldVersion::new(22, "producer_id", version).into());
173        }
174        if version >= 3 {
175            len += 2;
176        } else if self.producer_epoch != -1i16 {
177            return Err(UnsupportedFieldVersion::new(22, "producer_epoch", version).into());
178        }
179        if version >= 6 {
180            len += 1;
181        } else if self.enable2_pc != false {
182            return Err(UnsupportedFieldVersion::new(22, "enable2_pc", version).into());
183        }
184        if version >= 6 {
185            len += 1;
186        } else if self.keep_prepared_txn != false {
187            return Err(UnsupportedFieldVersion::new(22, "keep_prepared_txn", version).into());
188        }
189        if version >= 2 {
190            let mut all_tags: Vec<RawTaggedField> = self._unknown_tagged_fields.clone();
191            all_tags.sort_by_key(|f| f.tag);
192            len += tagged_fields_len(&all_tags)?;
193        }
194        Ok(len)
195    }
196}