Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
UnregisterBrokerRequest.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_i32, put_i32};
6use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
7use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
8
9pub const API_KEY: i16 = 64;
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 0;
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, Default)]
20pub struct UnregisterBrokerRequest {
21    pub broker_id: i32,
22    pub unknown_tagged_fields: UnknownTaggedFields,
23}
24impl Encode for UnregisterBrokerRequest {
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::UnsupportedVersion {
28                api_key: API_KEY,
29                version,
30            });
31        }
32        let flex = is_flexible(version);
33        if version >= 0 {
34            put_i32(buf, self.broker_id);
35        }
36        if flex {
37            let tagged = WriteTaggedFields::new();
38            tagged.write(buf, &self.unknown_tagged_fields);
39        }
40        Ok(())
41    }
42    fn encoded_len(&self, version: i16) -> usize {
43        let flex = is_flexible(version);
44        let mut n: usize = 0;
45        if version >= 0 {
46            n += 4;
47        }
48        if flex {
49            let known_pairs: Vec<(u32, usize)> = Vec::new();
50            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
51        }
52        n
53    }
54}
55impl Decode<'_> for UnregisterBrokerRequest {
56    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
57        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
58            return Err(ProtocolError::UnsupportedVersion {
59                api_key: API_KEY,
60                version,
61            });
62        }
63        let flex = is_flexible(version);
64        let mut out = Self::default();
65        if version >= 0 {
66            out.broker_id = get_i32(buf)?;
67        }
68        if flex {
69            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
70        }
71        Ok(out)
72    }
73}
74#[cfg(test)]
75impl UnregisterBrokerRequest {
76    #[must_use]
77    pub fn populated(version: i16) -> Self {
78        let mut m = Self::default();
79        if version >= 0 {
80            m.broker_id = 1i32;
81        }
82        m
83    }
84}
85
86/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
87/// Only includes fields valid for the given version.
88#[must_use]
89#[allow(unused_comparisons)]
90pub fn default_json(version: i16) -> ::serde_json::Value {
91    let mut obj = ::serde_json::Map::new();
92    obj.insert("brokerId".to_string(), ::serde_json::json!(0));
93    ::serde_json::Value::Object(obj)
94}
95
96impl crate::ProtocolRequest for UnregisterBrokerRequest {
97    const API_KEY: i16 = API_KEY;
98    const MIN_VERSION: i16 = MIN_VERSION;
99    const MAX_VERSION: i16 = MAX_VERSION;
100    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
101    type Response = super::unregister_broker_response::UnregisterBrokerResponse;
102}