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::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
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 { version >= FLEXIBLE_MIN }
16
17#[derive(Debug, Clone, PartialEq, Eq, Default)]
18pub struct UnregisterBrokerRequest {
19    pub broker_id: i32,
20    pub unknown_tagged_fields: UnknownTaggedFields,
21}
22
23impl Encode for UnregisterBrokerRequest {
24    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
25        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
26            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
27        }
28        let flex = is_flexible(version);
29        if version >= 0 { put_i32(buf, self.broker_id) }
30        if flex {
31            let tagged = WriteTaggedFields::new();
32            tagged.write(buf, &self.unknown_tagged_fields);
33        }
34        Ok(())
35    }
36    fn encoded_len(&self, version: i16) -> usize {
37        let flex = is_flexible(version);
38        let mut n: usize = 0;
39        if version >= 0 { n += 4; }
40        if flex {
41            let known_pairs: Vec<(u32, usize)> = Vec::new();
42            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
43        }
44        n
45    }
46}
47
48impl<'de> Decode<'de> for UnregisterBrokerRequest {
49    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
50        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
51            return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
52        }
53        let flex = is_flexible(version);
54        let mut out = Self::default();
55        if version >= 0 { out.broker_id = get_i32(buf)?; }
56        if flex {
57            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
58                Ok(false)
59            })?;
60        }
61        Ok(out)
62    }
63}
64
65/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
66/// Only includes fields valid for the given version.
67#[must_use]
68#[allow(unused_comparisons)]
69pub fn default_json(version: i16) -> ::serde_json::Value {
70    let mut obj = ::serde_json::Map::new();
71    obj.insert("brokerId".to_string(), ::serde_json::json!(0));
72    ::serde_json::Value::Object(obj)
73}
74
75impl crate::ProtocolRequest for UnregisterBrokerRequest {
76    const API_KEY: i16 = API_KEY;
77    const MIN_VERSION: i16 = MIN_VERSION;
78    const MAX_VERSION: i16 = MAX_VERSION;
79    const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
80    type Response = super::unregister_broker_response::UnregisterBrokerResponse;
81}