Skip to main content

odradek_protocol/messages/
init_producer_id_response.rs

1//! `InitProducerIdResponse` — generated from `schemas/InitProducerIdResponse.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 >= 2
25}
26
27/// `InitProducerIdResponse`, versions 0-6.
28#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct InitProducerIdResponse {
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 current producer id.
36    pub producer_id: i64,
37    /// The current epoch associated with the producer id.
38    pub producer_epoch: i16,
39    /// The producer id for ongoing transaction when KeepPreparedTxn is used, -1 if there is no transaction ongoing.
40    pub ongoing_txn_producer_id: i64,
41    /// The epoch associated with the  producer id for ongoing transaction when KeepPreparedTxn is used, -1 if there is no transaction ongoing.
42    pub ongoing_txn_producer_epoch: i16,
43    /// Tagged fields not (yet) known to this crate, kept raw.
44    pub unknown_tagged_fields: Vec<RawTaggedField>,
45}
46
47impl Default for InitProducerIdResponse {
48    fn default() -> Self {
49        Self {
50            throttle_time_ms: 0,
51            error_code: 0,
52            producer_id: -1,
53            producer_epoch: 0,
54            ongoing_txn_producer_id: -1,
55            ongoing_txn_producer_epoch: -1,
56            unknown_tagged_fields: Vec::new(),
57        }
58    }
59}
60
61impl InitProducerIdResponse {
62    /// This message's api key in Kafka's registry.
63    pub const API_KEY: i16 = 22;
64    /// The lowest schema version this snapshot can speak.
65    pub const MIN_VERSION: i16 = 0;
66    /// The highest schema version this snapshot can speak.
67    pub const MAX_VERSION: i16 = 6;
68
69    /// Encode this `InitProducerIdResponse` at `version`.
70    pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
71        buf.put_i32(self.throttle_time_ms);
72        buf.put_i16(self.error_code);
73        buf.put_i64(self.producer_id);
74        buf.put_i16(self.producer_epoch);
75        if version >= 6 {
76            buf.put_i64(self.ongoing_txn_producer_id);
77        }
78        if version >= 6 {
79            buf.put_i16(self.ongoing_txn_producer_epoch);
80        }
81        if is_flexible(version) {
82            wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
83        }
84        Ok(())
85    }
86
87    /// Decode one `InitProducerIdResponse`, bounding allocation by the default
88    /// [`Limits`] derived from `buf`'s remaining length.
89    pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
90        Self::decode_with_limits(buf, version, Limits::default())
91    }
92
93    /// Decode one `InitProducerIdResponse` under `limits`.
94    pub fn decode_with_limits(
95        buf: &mut impl Buf,
96        version: i16,
97        limits: Limits,
98    ) -> Result<Self, DecodeError> {
99        let mut budget = limits.budget(buf.remaining());
100        Self::decode_with_budget(buf, version, &mut budget)
101    }
102
103    /// Decode one `InitProducerIdResponse` against an existing `budget`.
104    pub fn decode_with_budget(
105        buf: &mut impl Buf,
106        version: i16,
107        budget: &mut Budget,
108    ) -> Result<Self, DecodeError> {
109        let mut this = Self::default();
110        this.throttle_time_ms = wire::get_i32(buf)?;
111        this.error_code = wire::get_i16(buf)?;
112        this.producer_id = wire::get_i64(buf)?;
113        this.producer_epoch = wire::get_i16(buf)?;
114        if version >= 6 {
115            this.ongoing_txn_producer_id = wire::get_i64(buf)?;
116        }
117        if version >= 6 {
118            this.ongoing_txn_producer_epoch = wire::get_i16(buf)?;
119        }
120        if is_flexible(version) {
121            this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
122        }
123        Ok(this)
124    }
125}
126
127impl crate::Message for InitProducerIdResponse {
128    const API_KEY: i16 = 22;
129    const MIN_VERSION: i16 = 0;
130    const MAX_VERSION: i16 = 6;
131
132    fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
133        InitProducerIdResponse::encode(self, buf, version)
134    }
135    fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
136        InitProducerIdResponse::decode(buf, version)
137    }
138    fn decode_with_limits(
139        buf: &mut impl Buf,
140        version: i16,
141        limits: Limits,
142    ) -> Result<Self, DecodeError> {
143        InitProducerIdResponse::decode_with_limits(buf, version, limits)
144    }
145    fn throttle_time_ms(&self) -> Option<i32> {
146        Some(self.throttle_time_ms)
147    }
148}