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 bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_bool, get_i16, get_i32, put_bool, put_i16, put_i32};
6use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
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 { version >= FLEXIBLE_MIN }
16
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct BrokerHeartbeatResponse {
19    pub throttle_time_ms: i32,
20    pub error_code: i16,
21    pub is_caught_up: bool,
22    pub is_fenced: bool,
23    pub should_shut_down: bool,
24    pub unknown_tagged_fields: UnknownTaggedFields,
25}
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: Default::default(),
36        }
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 { api_key: API_KEY, version });
44        }
45        let flex = is_flexible(version);
46        if version >= 0 { put_i32(buf, self.throttle_time_ms) }
47        if version >= 0 { put_i16(buf, self.error_code) }
48        if version >= 0 { put_bool(buf, self.is_caught_up) }
49        if version >= 0 { put_bool(buf, self.is_fenced) }
50        if version >= 0 { put_bool(buf, self.should_shut_down) }
51        if flex {
52            let tagged = WriteTaggedFields::new();
53            tagged.write(buf, &self.unknown_tagged_fields);
54        }
55        Ok(())
56    }
57    fn encoded_len(&self, version: i16) -> usize {
58        let flex = is_flexible(version);
59        let mut n: usize = 0;
60        if version >= 0 { n += 4; }
61        if version >= 0 { n += 2; }
62        if version >= 0 { n += 1; }
63        if version >= 0 { n += 1; }
64        if version >= 0 { n += 1; }
65        if flex {
66            let known_pairs: Vec<(u32, usize)> = Vec::new();
67            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
68        }
69        n
70    }
71}
72
73impl<'de> Decode<'de> for BrokerHeartbeatResponse {
74    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
75        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
76            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
77        }
78        let flex = is_flexible(version);
79        let mut out = Self::default();
80        if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
81        if version >= 0 { out.error_code = get_i16(buf)?; }
82        if version >= 0 { out.is_caught_up = get_bool(buf)?; }
83        if version >= 0 { out.is_fenced = get_bool(buf)?; }
84        if version >= 0 { out.should_shut_down = get_bool(buf)?; }
85        if flex {
86            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
87                Ok(false)
88            })?;
89        }
90        Ok(out)
91    }
92}
93
94/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
95/// Only includes fields valid for the given version.
96#[must_use]
97#[allow(unused_comparisons)]
98pub fn default_json(version: i16) -> ::serde_json::Value {
99    let mut obj = ::serde_json::Map::new();
100    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
101    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
102    obj.insert("isCaughtUp".to_string(), ::serde_json::Value::Bool(false));
103    obj.insert("isFenced".to_string(), ::serde_json::Value::Bool(true));
104    obj.insert("shouldShutDown".to_string(), ::serde_json::Value::Bool(false));
105    ::serde_json::Value::Object(obj)
106}