crabka_protocol/opt/rustwide/workdir/generated/
AddOffsetsToTxnResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
6use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
7use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
8
9pub const API_KEY: i16 = 25;
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 4;
12pub const FLEXIBLE_MIN: i16 = 3;
13
14#[inline]
15fn is_flexible(version: i16) -> bool {
16 version >= FLEXIBLE_MIN
17}
18
19#[derive(Debug, Clone, PartialEq, Eq, Default)]
20pub struct AddOffsetsToTxnResponse {
21 pub throttle_time_ms: i32,
22 pub error_code: i16,
23 pub unknown_tagged_fields: UnknownTaggedFields,
24}
25impl Encode for AddOffsetsToTxnResponse {
26 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
27 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
28 return Err(ProtocolError::UnsupportedVersion {
29 api_key: API_KEY,
30 version,
31 });
32 }
33 let flex = is_flexible(version);
34 if version >= 0 {
35 put_i32(buf, self.throttle_time_ms);
36 }
37 if version >= 0 {
38 put_i16(buf, self.error_code);
39 }
40 if flex {
41 let tagged = WriteTaggedFields::new();
42 tagged.write(buf, &self.unknown_tagged_fields);
43 }
44 Ok(())
45 }
46 fn encoded_len(&self, version: i16) -> usize {
47 let flex = is_flexible(version);
48 let mut n: usize = 0;
49 if version >= 0 {
50 n += 4;
51 }
52 if version >= 0 {
53 n += 2;
54 }
55 if flex {
56 let known_pairs: Vec<(u32, usize)> = Vec::new();
57 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
58 }
59 n
60 }
61}
62impl Decode<'_> for AddOffsetsToTxnResponse {
63 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
64 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
65 return Err(ProtocolError::UnsupportedVersion {
66 api_key: API_KEY,
67 version,
68 });
69 }
70 let flex = is_flexible(version);
71 let mut out = Self::default();
72 if version >= 0 {
73 out.throttle_time_ms = get_i32(buf)?;
74 }
75 if version >= 0 {
76 out.error_code = get_i16(buf)?;
77 }
78 if flex {
79 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
80 }
81 Ok(out)
82 }
83}
84#[cfg(test)]
85impl AddOffsetsToTxnResponse {
86 #[must_use]
87 pub fn populated(version: i16) -> Self {
88 let mut m = Self::default();
89 if version >= 0 {
90 m.throttle_time_ms = 1i32;
91 }
92 if version >= 0 {
93 m.error_code = 1i16;
94 }
95 m
96 }
97}
98
99#[must_use]
102#[allow(unused_comparisons)]
103pub fn default_json(version: i16) -> ::serde_json::Value {
104 let mut obj = ::serde_json::Map::new();
105 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
106 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
107 ::serde_json::Value::Object(obj)
108}