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