crabka_protocol/opt/rustwide/workdir/generated/
BrokerHeartbeatResponse.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, get_i16, get_i32, put_bool, 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 = 63;
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 2;
12pub const FLEXIBLE_MIN: i16 = 0;
13
14#[inline]
15fn is_flexible(version: i16) -> bool {
16 version >= FLEXIBLE_MIN
17}
18
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub struct BrokerHeartbeatResponse {
21 pub throttle_time_ms: i32,
22 pub error_code: i16,
23 pub is_caught_up: bool,
24 pub is_fenced: bool,
25 pub should_shut_down: bool,
26 pub unknown_tagged_fields: UnknownTaggedFields,
27}
28impl Default for BrokerHeartbeatResponse {
29 fn default() -> Self {
30 Self {
31 throttle_time_ms: 0i32,
32 error_code: 0i16,
33 is_caught_up: false,
34 is_fenced: true,
35 should_shut_down: false,
36 unknown_tagged_fields: Default::default(),
37 }
38 }
39}
40impl Encode for BrokerHeartbeatResponse {
41 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
42 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
43 return Err(ProtocolError::UnsupportedVersion {
44 api_key: API_KEY,
45 version,
46 });
47 }
48 let flex = is_flexible(version);
49 if version >= 0 {
50 put_i32(buf, self.throttle_time_ms);
51 }
52 if version >= 0 {
53 put_i16(buf, self.error_code);
54 }
55 if version >= 0 {
56 put_bool(buf, self.is_caught_up);
57 }
58 if version >= 0 {
59 put_bool(buf, self.is_fenced);
60 }
61 if version >= 0 {
62 put_bool(buf, self.should_shut_down);
63 }
64 if flex {
65 let tagged = WriteTaggedFields::new();
66 tagged.write(buf, &self.unknown_tagged_fields);
67 }
68 Ok(())
69 }
70 fn encoded_len(&self, version: i16) -> usize {
71 let flex = is_flexible(version);
72 let mut n: usize = 0;
73 if version >= 0 {
74 n += 4;
75 }
76 if version >= 0 {
77 n += 2;
78 }
79 if version >= 0 {
80 n += 1;
81 }
82 if version >= 0 {
83 n += 1;
84 }
85 if version >= 0 {
86 n += 1;
87 }
88 if flex {
89 let known_pairs: Vec<(u32, usize)> = Vec::new();
90 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
91 }
92 n
93 }
94}
95impl Decode<'_> for BrokerHeartbeatResponse {
96 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
97 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
98 return Err(ProtocolError::UnsupportedVersion {
99 api_key: API_KEY,
100 version,
101 });
102 }
103 let flex = is_flexible(version);
104 let mut out = Self::default();
105 if version >= 0 {
106 out.throttle_time_ms = get_i32(buf)?;
107 }
108 if version >= 0 {
109 out.error_code = get_i16(buf)?;
110 }
111 if version >= 0 {
112 out.is_caught_up = get_bool(buf)?;
113 }
114 if version >= 0 {
115 out.is_fenced = get_bool(buf)?;
116 }
117 if version >= 0 {
118 out.should_shut_down = get_bool(buf)?;
119 }
120 if flex {
121 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
122 }
123 Ok(out)
124 }
125}
126#[cfg(test)]
127impl BrokerHeartbeatResponse {
128 #[must_use]
129 pub fn populated(version: i16) -> Self {
130 let mut m = Self::default();
131 if version >= 0 {
132 m.throttle_time_ms = 1i32;
133 }
134 if version >= 0 {
135 m.error_code = 1i16;
136 }
137 if version >= 0 {
138 m.is_caught_up = true;
139 }
140 if version >= 0 {
141 m.is_fenced = true;
142 }
143 if version >= 0 {
144 m.should_shut_down = true;
145 }
146 m
147 }
148}
149
150#[must_use]
153#[allow(unused_comparisons)]
154pub fn default_json(version: i16) -> ::serde_json::Value {
155 let mut obj = ::serde_json::Map::new();
156 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
157 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
158 obj.insert("isCaughtUp".to_string(), ::serde_json::Value::Bool(false));
159 obj.insert("isFenced".to_string(), ::serde_json::Value::Bool(true));
160 obj.insert(
161 "shouldShutDown".to_string(),
162 ::serde_json::Value::Bool(false),
163 );
164 ::serde_json::Value::Object(obj)
165}