odradek_protocol/messages/
txn_offset_commit_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 TxnOffsetCommitResponse {
31 pub throttle_time_ms: i32,
33 pub topics: Vec<TxnOffsetCommitResponseTopic>,
35 pub unknown_tagged_fields: Vec<RawTaggedField>,
37}
38
39impl Default for TxnOffsetCommitResponse {
40 fn default() -> Self {
41 Self {
42 throttle_time_ms: 0,
43 topics: Vec::new(),
44 unknown_tagged_fields: Vec::new(),
45 }
46 }
47}
48
49impl TxnOffsetCommitResponse {
50 pub const API_KEY: i16 = 28;
52 pub const MIN_VERSION: i16 = 0;
54 pub const MAX_VERSION: i16 = 5;
56
57 pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
59 buf.put_i32(self.throttle_time_ms);
60 if is_flexible(version) {
61 wire::put_compact_array_len(buf, Some(self.topics.len()));
62 } else {
63 wire::put_array_len(buf, Some(self.topics.len()))?;
64 }
65 for item in &self.topics {
66 item.encode(buf, version)?;
67 }
68 if is_flexible(version) {
69 wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
70 }
71 Ok(())
72 }
73
74 pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
77 Self::decode_with_limits(buf, version, Limits::default())
78 }
79
80 pub fn decode_with_limits(
82 buf: &mut impl Buf,
83 version: i16,
84 limits: Limits,
85 ) -> Result<Self, DecodeError> {
86 let mut budget = limits.budget(buf.remaining());
87 Self::decode_with_budget(buf, version, &mut budget)
88 }
89
90 pub fn decode_with_budget(
92 buf: &mut impl Buf,
93 version: i16,
94 budget: &mut Budget,
95 ) -> Result<Self, DecodeError> {
96 let mut this = Self::default();
97 this.throttle_time_ms = wire::get_i32(buf)?;
98 this.topics = {
99 let len = if is_flexible(version) {
100 wire::get_compact_array_len(buf)?
101 } else {
102 wire::get_array_len(buf)?
103 };
104 match len {
105 None => return Err(DecodeError::InvalidLength(-1)),
106 Some(n) => {
107 let mut items = Vec::new();
108 for _ in 0..n {
109 let mark = buf.remaining();
110 let item =
111 TxnOffsetCommitResponseTopic::decode_with_budget(buf, version, budget)?;
112 budget.progress(mark, buf.remaining())?;
113 budget.push(&mut items, item)?;
114 }
115 items
116 }
117 }
118 };
119 if is_flexible(version) {
120 this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
121 }
122 Ok(this)
123 }
124}
125
126impl crate::Message for TxnOffsetCommitResponse {
127 const API_KEY: i16 = 28;
128 const MIN_VERSION: i16 = 0;
129 const MAX_VERSION: i16 = 5;
130
131 fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
132 TxnOffsetCommitResponse::encode(self, buf, version)
133 }
134 fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
135 TxnOffsetCommitResponse::decode(buf, version)
136 }
137 fn decode_with_limits(
138 buf: &mut impl Buf,
139 version: i16,
140 limits: Limits,
141 ) -> Result<Self, DecodeError> {
142 TxnOffsetCommitResponse::decode_with_limits(buf, version, limits)
143 }
144 fn throttle_time_ms(&self) -> Option<i32> {
145 Some(self.throttle_time_ms)
146 }
147}
148
149#[derive(Debug, Clone, PartialEq)]
151#[non_exhaustive]
152pub struct TxnOffsetCommitResponseTopic {
153 pub name: String,
155 pub partitions: Vec<TxnOffsetCommitResponsePartition>,
157 pub unknown_tagged_fields: Vec<RawTaggedField>,
159}
160
161impl Default for TxnOffsetCommitResponseTopic {
162 fn default() -> Self {
163 Self {
164 name: String::new(),
165 partitions: Vec::new(),
166 unknown_tagged_fields: Vec::new(),
167 }
168 }
169}
170
171impl TxnOffsetCommitResponseTopic {
172 pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
174 if is_flexible(version) {
175 wire::put_compact_string(buf, &self.name);
176 } else {
177 wire::put_string(buf, &self.name)?;
178 }
179 if is_flexible(version) {
180 wire::put_compact_array_len(buf, Some(self.partitions.len()));
181 } else {
182 wire::put_array_len(buf, Some(self.partitions.len()))?;
183 }
184 for item in &self.partitions {
185 item.encode(buf, version)?;
186 }
187 if is_flexible(version) {
188 wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
189 }
190 Ok(())
191 }
192
193 pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
196 Self::decode_with_limits(buf, version, Limits::default())
197 }
198
199 pub fn decode_with_limits(
201 buf: &mut impl Buf,
202 version: i16,
203 limits: Limits,
204 ) -> Result<Self, DecodeError> {
205 let mut budget = limits.budget(buf.remaining());
206 Self::decode_with_budget(buf, version, &mut budget)
207 }
208
209 pub fn decode_with_budget(
211 buf: &mut impl Buf,
212 version: i16,
213 budget: &mut Budget,
214 ) -> Result<Self, DecodeError> {
215 let mut this = Self::default();
216 this.name = if is_flexible(version) {
217 wire::get_compact_string(buf)?
218 } else {
219 wire::get_string(buf)?
220 };
221 this.partitions = {
222 let len = if is_flexible(version) {
223 wire::get_compact_array_len(buf)?
224 } else {
225 wire::get_array_len(buf)?
226 };
227 match len {
228 None => return Err(DecodeError::InvalidLength(-1)),
229 Some(n) => {
230 let mut items = Vec::new();
231 for _ in 0..n {
232 let mark = buf.remaining();
233 let item = TxnOffsetCommitResponsePartition::decode_with_budget(
234 buf, version, budget,
235 )?;
236 budget.progress(mark, buf.remaining())?;
237 budget.push(&mut items, item)?;
238 }
239 items
240 }
241 }
242 };
243 if is_flexible(version) {
244 this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
245 }
246 Ok(this)
247 }
248}
249
250#[derive(Debug, Clone, PartialEq)]
252#[non_exhaustive]
253pub struct TxnOffsetCommitResponsePartition {
254 pub partition_index: i32,
256 pub error_code: i16,
258 pub unknown_tagged_fields: Vec<RawTaggedField>,
260}
261
262impl Default for TxnOffsetCommitResponsePartition {
263 fn default() -> Self {
264 Self {
265 partition_index: 0,
266 error_code: 0,
267 unknown_tagged_fields: Vec::new(),
268 }
269 }
270}
271
272impl TxnOffsetCommitResponsePartition {
273 pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
275 buf.put_i32(self.partition_index);
276 buf.put_i16(self.error_code);
277 if is_flexible(version) {
278 wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
279 }
280 Ok(())
281 }
282
283 pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
286 Self::decode_with_limits(buf, version, Limits::default())
287 }
288
289 pub fn decode_with_limits(
291 buf: &mut impl Buf,
292 version: i16,
293 limits: Limits,
294 ) -> Result<Self, DecodeError> {
295 let mut budget = limits.budget(buf.remaining());
296 Self::decode_with_budget(buf, version, &mut budget)
297 }
298
299 pub fn decode_with_budget(
301 buf: &mut impl Buf,
302 version: i16,
303 budget: &mut Budget,
304 ) -> Result<Self, DecodeError> {
305 let mut this = Self::default();
306 this.partition_index = wire::get_i32(buf)?;
307 this.error_code = wire::get_i16(buf)?;
308 if is_flexible(version) {
309 this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
310 }
311 Ok(this)
312 }
313}