Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
BrokerHeartbeatResponse.borrowed.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::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::{DecodeBorrow, 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 BrokerHeartbeatResponse {
41    pub fn to_owned(&self) -> crate::owned::broker_heartbeat_response::BrokerHeartbeatResponse {
42        crate::owned::broker_heartbeat_response::BrokerHeartbeatResponse {
43            throttle_time_ms: (self.throttle_time_ms),
44            error_code: (self.error_code),
45            is_caught_up: (self.is_caught_up),
46            is_fenced: (self.is_fenced),
47            should_shut_down: (self.should_shut_down),
48            unknown_tagged_fields: self.unknown_tagged_fields.clone(),
49        }
50    }
51}
52impl Encode for BrokerHeartbeatResponse {
53    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
54        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
55            return Err(ProtocolError::UnsupportedVersion {
56                api_key: API_KEY,
57                version,
58            });
59        }
60        let flex = is_flexible(version);
61        if version >= 0 {
62            put_i32(buf, self.throttle_time_ms);
63        }
64        if version >= 0 {
65            put_i16(buf, self.error_code);
66        }
67        if version >= 0 {
68            put_bool(buf, self.is_caught_up);
69        }
70        if version >= 0 {
71            put_bool(buf, self.is_fenced);
72        }
73        if version >= 0 {
74            put_bool(buf, self.should_shut_down);
75        }
76        if flex {
77            let tagged = WriteTaggedFields::new();
78            tagged.write(buf, &self.unknown_tagged_fields);
79        }
80        Ok(())
81    }
82    fn encoded_len(&self, version: i16) -> usize {
83        let flex = is_flexible(version);
84        let mut n: usize = 0;
85        if version >= 0 {
86            n += 4;
87        }
88        if version >= 0 {
89            n += 2;
90        }
91        if version >= 0 {
92            n += 1;
93        }
94        if version >= 0 {
95            n += 1;
96        }
97        if version >= 0 {
98            n += 1;
99        }
100        if flex {
101            let known_pairs: Vec<(u32, usize)> = Vec::new();
102            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
103        }
104        n
105    }
106}
107impl<'de> DecodeBorrow<'de> for BrokerHeartbeatResponse {
108    fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
109        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
110            return Err(ProtocolError::UnsupportedVersion {
111                api_key: API_KEY,
112                version,
113            });
114        }
115        let flex = is_flexible(version);
116        let mut out = Self::default();
117        if version >= 0 {
118            out.throttle_time_ms = get_i32(buf)?;
119        }
120        if version >= 0 {
121            out.error_code = get_i16(buf)?;
122        }
123        if version >= 0 {
124            out.is_caught_up = get_bool(buf)?;
125        }
126        if version >= 0 {
127            out.is_fenced = get_bool(buf)?;
128        }
129        if version >= 0 {
130            out.should_shut_down = get_bool(buf)?;
131        }
132        if flex {
133            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
134        }
135        Ok(out)
136    }
137}
138#[cfg(test)]
139impl BrokerHeartbeatResponse {
140    #[must_use]
141    pub fn populated(version: i16) -> Self {
142        let mut m = Self::default();
143        if version >= 0 {
144            m.throttle_time_ms = 1i32;
145        }
146        if version >= 0 {
147            m.error_code = 1i16;
148        }
149        if version >= 0 {
150            m.is_caught_up = true;
151        }
152        if version >= 0 {
153            m.is_fenced = true;
154        }
155        if version >= 0 {
156            m.should_shut_down = true;
157        }
158        m
159    }
160}