Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
UnregisterBrokerRecord.owned.rs

1// AUTO-GENERATED by krabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::{
6    Decode, Encode, ProtocolError, UnknownTaggedFields,
7    primitives::fixed::{get_i32, get_i64, put_i32, put_i64},
8    tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
9};
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 0;
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, Default)]
19pub struct UnregisterBrokerRecord {
20    pub broker_id: i32,
21    pub broker_epoch: i64,
22    pub unknown_tagged_fields: UnknownTaggedFields,
23}
24impl Encode for UnregisterBrokerRecord {
25    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
26        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
27            return Err(ProtocolError::SchemaMismatch(
28                "UnregisterBrokerRecord version out of range",
29            ));
30        }
31        let flex = is_flexible(version);
32        if version >= 0 {
33            put_i32(buf, self.broker_id);
34        }
35        if version >= 0 {
36            put_i64(buf, self.broker_epoch);
37        }
38        if flex {
39            let tagged = WriteTaggedFields::new();
40            tagged.write(buf, &self.unknown_tagged_fields);
41        }
42        Ok(())
43    }
44    fn encoded_len(&self, version: i16) -> usize {
45        let flex = is_flexible(version);
46        let mut n: usize = 0;
47        if version >= 0 {
48            n += 4;
49        }
50        if version >= 0 {
51            n += 8;
52        }
53        if flex {
54            let known_pairs: Vec<(u32, usize)> = Vec::new();
55            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
56        }
57        n
58    }
59}
60impl Decode<'_> for UnregisterBrokerRecord {
61    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
62        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
63            return Err(ProtocolError::SchemaMismatch(
64                "UnregisterBrokerRecord version out of range",
65            ));
66        }
67        let flex = is_flexible(version);
68        let mut out = Self::default();
69        if version >= 0 {
70            out.broker_id = get_i32(buf)?;
71        }
72        if version >= 0 {
73            out.broker_epoch = get_i64(buf)?;
74        }
75        if flex {
76            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
77        }
78        Ok(out)
79    }
80}
81#[cfg(test)]
82impl UnregisterBrokerRecord {
83    #[must_use]
84    pub fn populated(version: i16) -> Self {
85        let mut m = Self::default();
86        if version >= 0 {
87            m.broker_id = 1i32;
88        }
89        if version >= 0 {
90            m.broker_epoch = 1i64;
91        }
92        m
93    }
94}
95/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
96/// Only includes fields valid for the given version.
97#[must_use]
98#[allow(unused_comparisons)]
99pub fn default_json(_version: i16) -> ::serde_json::Value {
100    let mut obj = ::serde_json::Map::new();
101    obj.insert("brokerId".to_string(), ::serde_json::json!(0));
102    obj.insert("brokerEpoch".to_string(), ::serde_json::json!(0));
103    ::serde_json::Value::Object(obj)
104}