odradek_protocol/messages/
add_offsets_to_txn_response.rs1#![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
21pub fn is_flexible(version: i16) -> bool {
23 let _ = version;
24 version >= 3
25}
26
27#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct AddOffsetsToTxnResponse {
31 pub throttle_time_ms: i32,
33 pub error_code: i16,
35 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 pub const API_KEY: i16 = 25;
52 pub const MIN_VERSION: i16 = 0;
54 pub const MAX_VERSION: i16 = 4;
56
57 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 pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
70 Self::decode_with_limits(buf, version, Limits::default())
71 }
72
73 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 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}