Skip to main content

odradek_protocol/messages/
add_offsets_to_txn_response.rs

1//! `AddOffsetsToTxnResponse` — generated from `schemas/AddOffsetsToTxnResponse.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/// `AddOffsetsToTxnResponse`, versions 0-4.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct AddOffsetsToTxnResponse {
31    /// 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 response error code, or 0 if there was no error.
34    pub error_code: i16,
35    /// Tagged fields not (yet) known to this crate, kept raw.
36    pub unknown_tagged_fields: Vec<RawTaggedField>,
37}
38
39impl Default for AddOffsetsToTxnResponse {
40    fn default() -> Self {
41        Self {
42            throttle_time_ms: 0,
43            error_code: 0,
44            unknown_tagged_fields: Vec::new(),
45        }
46    }
47}
48
49impl AddOffsetsToTxnResponse {
50    /// This message's api key in Kafka's registry.
51    pub const API_KEY: i16 = 25;
52    /// The lowest schema version this snapshot can speak.
53    pub const MIN_VERSION: i16 = 0;
54    /// The highest schema version this snapshot can speak.
55    pub const MAX_VERSION: i16 = 4;
56
57    /// Encode this `AddOffsetsToTxnResponse` at `version`.
58    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
59        buf.put_i32(self.throttle_time_ms);
60        buf.put_i16(self.error_code);
61        if is_flexible(version) {
62            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
63        }
64        Ok(())
65    }
66
67    /// Decode one `AddOffsetsToTxnResponse`, bounding allocation by the default
68    /// [`Limits`] derived from `buf`'s remaining length.
69    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
70        Self::decode_with_limits(buf, version, Limits::default())
71    }
72
73    /// Decode one `AddOffsetsToTxnResponse` under `limits`.
74    pub fn decode_with_limits(
75        buf: &mut impl Buf,
76        version: i16,
77        limits: Limits,
78    ) -> Result<Self, DecodeError> {
79        let mut budget = limits.budget(buf.remaining());
80        Self::decode_with_budget(buf, version, &mut budget)
81    }
82
83    /// Decode one `AddOffsetsToTxnResponse` against an existing `budget`.
84    pub fn decode_with_budget(
85        buf: &mut impl Buf,
86        version: i16,
87        budget: &mut Budget,
88    ) -> Result<Self, DecodeError> {
89        let mut this = Self::default();
90        this.throttle_time_ms = wire::get_i32(buf)?;
91        this.error_code = wire::get_i16(buf)?;
92        if is_flexible(version) {
93            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
94        }
95        Ok(this)
96    }
97}
98
99impl crate::Message for AddOffsetsToTxnResponse {
100    const API_KEY: i16 = 25;
101    const MIN_VERSION: i16 = 0;
102    const MAX_VERSION: i16 = 4;
103
104    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
105        AddOffsetsToTxnResponse::encode(self, buf, version)
106    }
107    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
108        AddOffsetsToTxnResponse::decode(buf, version)
109    }
110    fn decode_with_limits(
111        buf: &mut impl Buf,
112        version: i16,
113        limits: Limits,
114    ) -> Result<Self, DecodeError> {
115        AddOffsetsToTxnResponse::decode_with_limits(buf, version, limits)
116    }
117    fn throttle_time_ms(&self) -> Option<i32> {
118        Some(self.throttle_time_ms)
119    }
120}