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