Skip to main content

odradek_protocol/messages/
add_offsets_to_txn_request.rs

1//! `AddOffsetsToTxnRequest` — generated from `schemas/AddOffsetsToTxnRequest.json`.
2//!
3//! @generated by `cargo xtask codegen`. Do not edit by hand.
4
5#![allow(
6    clippy::field_reassign_with_default,
7    clippy::nonminimal_bool,
8    clippy::derivable_impls,
9    clippy::borrow_deref_ref,
10    clippy::double_parens,
11    unused_parens
12)]
13
14use bytes::{Buf, BufMut};
15
16use crate::budget::{Budget, Limits};
17#[allow(unused_imports)]
18use crate::error::{DecodeError, EncodeError};
19use crate::wire::{self, RawTaggedField};
20
21/// Whether `version` of this message uses the flexible (compact) encoding.
22pub fn is_flexible(version: i16) -> bool {
23    let _ = version;
24    version >= 3
25}
26
27/// `AddOffsetsToTxnRequest`, versions 0-4.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct AddOffsetsToTxnRequest {
31    /// The transactional id corresponding to the transaction.
32    pub transactional_id: String,
33    /// Current producer id in use by the transactional id.
34    pub producer_id: i64,
35    /// Current epoch associated with the producer id.
36    pub producer_epoch: i16,
37    /// The unique group identifier.
38    pub group_id: String,
39    /// Tagged fields not (yet) known to this crate, kept raw.
40    pub unknown_tagged_fields: Vec<RawTaggedField>,
41}
42
43impl Default for AddOffsetsToTxnRequest {
44    fn default() -> Self {
45        Self {
46            transactional_id: String::new(),
47            producer_id: 0,
48            producer_epoch: 0,
49            group_id: String::new(),
50            unknown_tagged_fields: Vec::new(),
51        }
52    }
53}
54
55impl AddOffsetsToTxnRequest {
56    /// This message's api key in Kafka's registry.
57    pub const API_KEY: i16 = 25;
58    /// The lowest schema version this snapshot can speak.
59    pub const MIN_VERSION: i16 = 0;
60    /// The highest schema version this snapshot can speak.
61    pub const MAX_VERSION: i16 = 4;
62
63    /// Encode this `AddOffsetsToTxnRequest` at `version`.
64    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
65        if is_flexible(version) {
66            wire::put_compact_string(buf, &self.transactional_id);
67        } else {
68            wire::put_string(buf, &self.transactional_id)?;
69        }
70        buf.put_i64(self.producer_id);
71        buf.put_i16(self.producer_epoch);
72        if is_flexible(version) {
73            wire::put_compact_string(buf, &self.group_id);
74        } else {
75            wire::put_string(buf, &self.group_id)?;
76        }
77        if is_flexible(version) {
78            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
79        }
80        Ok(())
81    }
82
83    /// Decode one `AddOffsetsToTxnRequest`, bounding allocation by the default
84    /// [`Limits`] derived from `buf`'s remaining length.
85    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
86        Self::decode_with_limits(buf, version, Limits::default())
87    }
88
89    /// Decode one `AddOffsetsToTxnRequest` under `limits`.
90    pub fn decode_with_limits(
91        buf: &mut impl Buf,
92        version: i16,
93        limits: Limits,
94    ) -> Result<Self, DecodeError> {
95        let mut budget = limits.budget(buf.remaining());
96        Self::decode_with_budget(buf, version, &mut budget)
97    }
98
99    /// Decode one `AddOffsetsToTxnRequest` against an existing `budget`.
100    pub fn decode_with_budget(
101        buf: &mut impl Buf,
102        version: i16,
103        budget: &mut Budget,
104    ) -> Result<Self, DecodeError> {
105        let mut this = Self::default();
106        this.transactional_id = if is_flexible(version) {
107            wire::get_compact_string(buf)?
108        } else {
109            wire::get_string(buf)?
110        };
111        this.producer_id = wire::get_i64(buf)?;
112        this.producer_epoch = wire::get_i16(buf)?;
113        this.group_id = if is_flexible(version) {
114            wire::get_compact_string(buf)?
115        } else {
116            wire::get_string(buf)?
117        };
118        if is_flexible(version) {
119            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
120        }
121        Ok(this)
122    }
123}
124
125impl crate::Message for AddOffsetsToTxnRequest {
126    const API_KEY: i16 = 25;
127    const MIN_VERSION: i16 = 0;
128    const MAX_VERSION: i16 = 4;
129
130    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
131        AddOffsetsToTxnRequest::encode(self, buf, version)
132    }
133    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
134        AddOffsetsToTxnRequest::decode(buf, version)
135    }
136    fn decode_with_limits(
137        buf: &mut impl Buf,
138        version: i16,
139        limits: Limits,
140    ) -> Result<Self, DecodeError> {
141        AddOffsetsToTxnRequest::decode_with_limits(buf, version, limits)
142    }
143}