Skip to main content

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

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