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