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