Skip to main content

odradek_protocol/messages/
end_txn_response.rs

1//! `EndTxnResponse` — generated from `schemas/EndTxnResponse.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/// `EndTxnResponse`, versions 0-5.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct EndTxnResponse {
31    /// The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
32    pub throttle_time_ms: i32,
33    /// The error code, or 0 if there was no error.
34    pub error_code: i16,
35    /// The producer ID.
36    pub producer_id: i64,
37    /// The current epoch associated with the producer.
38    pub producer_epoch: i16,
39    /// Tagged fields not (yet) known to this crate, kept raw.
40    pub unknown_tagged_fields: Vec<RawTaggedField>,
41}
42
43impl Default for EndTxnResponse {
44    fn default() -> Self {
45        Self {
46            throttle_time_ms: 0,
47            error_code: 0,
48            producer_id: -1,
49            producer_epoch: -1,
50            unknown_tagged_fields: Vec::new(),
51        }
52    }
53}
54
55impl EndTxnResponse {
56    /// This message's api key in Kafka's registry.
57    pub const API_KEY: i16 = 26;
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 = 5;
62
63    /// Encode this `EndTxnResponse` at `version`.
64    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
65        buf.put_i32(self.throttle_time_ms);
66        buf.put_i16(self.error_code);
67        if version >= 5 {
68            buf.put_i64(self.producer_id);
69        }
70        if version >= 5 {
71            buf.put_i16(self.producer_epoch);
72        }
73        if is_flexible(version) {
74            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
75        }
76        Ok(())
77    }
78
79    /// Decode one `EndTxnResponse`, bounding allocation by the default
80    /// [`Limits`] derived from `buf`'s remaining length.
81    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
82        Self::decode_with_limits(buf, version, Limits::default())
83    }
84
85    /// Decode one `EndTxnResponse` under `limits`.
86    pub fn decode_with_limits(
87        buf: &mut impl Buf,
88        version: i16,
89        limits: Limits,
90    ) -> Result<Self, DecodeError> {
91        let mut budget = limits.budget(buf.remaining());
92        Self::decode_with_budget(buf, version, &mut budget)
93    }
94
95    /// Decode one `EndTxnResponse` against an existing `budget`.
96    pub fn decode_with_budget(
97        buf: &mut impl Buf,
98        version: i16,
99        budget: &mut Budget,
100    ) -> Result<Self, DecodeError> {
101        let mut this = Self::default();
102        this.throttle_time_ms = wire::get_i32(buf)?;
103        this.error_code = wire::get_i16(buf)?;
104        if version >= 5 {
105            this.producer_id = wire::get_i64(buf)?;
106        }
107        if version >= 5 {
108            this.producer_epoch = wire::get_i16(buf)?;
109        }
110        if is_flexible(version) {
111            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
112        }
113        Ok(this)
114    }
115}
116
117impl crate::Message for EndTxnResponse {
118    const API_KEY: i16 = 26;
119    const MIN_VERSION: i16 = 0;
120    const MAX_VERSION: i16 = 5;
121
122    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
123        EndTxnResponse::encode(self, buf, version)
124    }
125    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
126        EndTxnResponse::decode(buf, version)
127    }
128    fn decode_with_limits(
129        buf: &mut impl Buf,
130        version: i16,
131        limits: Limits,
132    ) -> Result<Self, DecodeError> {
133        EndTxnResponse::decode_with_limits(buf, version, limits)
134    }
135    fn throttle_time_ms(&self) -> Option<i32> {
136        Some(self.throttle_time_ms)
137    }
138}