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::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
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 { version >= FLEXIBLE_MIN }
16
17#[derive(Debug, Clone, PartialEq, Eq, Default)]
18pub struct AddOffsetsToTxnResponse {
19 pub throttle_time_ms: i32,
20 pub error_code: i16,
21 pub unknown_tagged_fields: UnknownTaggedFields,
22}
23
24impl Encode for AddOffsetsToTxnResponse {
25 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
26 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
27 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
28 }
29 let flex = is_flexible(version);
30 if version >= 0 { put_i32(buf, self.throttle_time_ms) }
31 if version >= 0 { put_i16(buf, self.error_code) }
32 if flex {
33 let tagged = WriteTaggedFields::new();
34 tagged.write(buf, &self.unknown_tagged_fields);
35 }
36 Ok(())
37 }
38 fn encoded_len(&self, version: i16) -> usize {
39 let flex = is_flexible(version);
40 let mut n: usize = 0;
41 if version >= 0 { n += 4; }
42 if version >= 0 { n += 2; }
43 if flex {
44 let known_pairs: Vec<(u32, usize)> = Vec::new();
45 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
46 }
47 n
48 }
49}
50
51impl<'de> Decode<'de> for AddOffsetsToTxnResponse {
52 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
53 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
54 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
55 }
56 let flex = is_flexible(version);
57 let mut out = Self::default();
58 if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
59 if version >= 0 { out.error_code = get_i16(buf)?; }
60 if flex {
61 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
62 Ok(false)
63 })?;
64 }
65 Ok(out)
66 }
67}
68
69#[must_use]
72#[allow(unused_comparisons)]
73pub fn default_json(version: i16) -> ::serde_json::Value {
74 let mut obj = ::serde_json::Map::new();
75 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
76 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
77 ::serde_json::Value::Object(obj)
78}