Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
UnregisterBrokerResponse.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_i16, get_i32, put_i16, put_i32};
6use crate::primitives::string_bytes::{
7    compact_nullable_string_len, get_compact_nullable_string_owned, get_nullable_string_owned,
8    nullable_string_len, put_compact_nullable_string, put_nullable_string,
9};
10use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 64;
14pub const MIN_VERSION: i16 = 0;
15pub const MAX_VERSION: i16 = 0;
16pub const FLEXIBLE_MIN: i16 = 0;
17
18#[inline]
19fn is_flexible(version: i16) -> bool {
20    version >= FLEXIBLE_MIN
21}
22
23#[derive(Debug, Clone, PartialEq, Eq, Default)]
24pub struct UnregisterBrokerResponse {
25    pub throttle_time_ms: i32,
26    pub error_code: i16,
27    pub error_message: Option<String>,
28    pub unknown_tagged_fields: UnknownTaggedFields,
29}
30impl Encode for UnregisterBrokerResponse {
31    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
32        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
33            return Err(ProtocolError::UnsupportedVersion {
34                api_key: API_KEY,
35                version,
36            });
37        }
38        let flex = is_flexible(version);
39        if version >= 0 {
40            put_i32(buf, self.throttle_time_ms);
41        }
42        if version >= 0 {
43            put_i16(buf, self.error_code);
44        }
45        if version >= 0 {
46            if flex {
47                put_compact_nullable_string(buf, self.error_message.as_deref());
48            } else {
49                put_nullable_string(buf, self.error_message.as_deref());
50            }
51        }
52        if flex {
53            let tagged = WriteTaggedFields::new();
54            tagged.write(buf, &self.unknown_tagged_fields);
55        }
56        Ok(())
57    }
58    fn encoded_len(&self, version: i16) -> usize {
59        let flex = is_flexible(version);
60        let mut n: usize = 0;
61        if version >= 0 {
62            n += 4;
63        }
64        if version >= 0 {
65            n += 2;
66        }
67        if version >= 0 {
68            n += if flex {
69                compact_nullable_string_len(self.error_message.as_deref())
70            } else {
71                nullable_string_len(self.error_message.as_deref())
72            };
73        }
74        if flex {
75            let known_pairs: Vec<(u32, usize)> = Vec::new();
76            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
77        }
78        n
79    }
80}
81impl Decode<'_> for UnregisterBrokerResponse {
82    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
83        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
84            return Err(ProtocolError::UnsupportedVersion {
85                api_key: API_KEY,
86                version,
87            });
88        }
89        let flex = is_flexible(version);
90        let mut out = Self::default();
91        if version >= 0 {
92            out.throttle_time_ms = get_i32(buf)?;
93        }
94        if version >= 0 {
95            out.error_code = get_i16(buf)?;
96        }
97        if version >= 0 {
98            out.error_message = if flex {
99                get_compact_nullable_string_owned(buf)?
100            } else {
101                get_nullable_string_owned(buf)?
102            };
103        }
104        if flex {
105            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
106        }
107        Ok(out)
108    }
109}
110#[cfg(test)]
111impl UnregisterBrokerResponse {
112    #[must_use]
113    pub fn populated(version: i16) -> Self {
114        let mut m = Self::default();
115        if version >= 0 {
116            m.throttle_time_ms = 1i32;
117        }
118        if version >= 0 {
119            m.error_code = 1i16;
120        }
121        if version >= 0 {
122            m.error_message = Some("x".to_string());
123        }
124        m
125    }
126}
127
128/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
129/// Only includes fields valid for the given version.
130#[must_use]
131#[allow(unused_comparisons)]
132pub fn default_json(version: i16) -> ::serde_json::Value {
133    let mut obj = ::serde_json::Map::new();
134    obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
135    obj.insert("errorCode".to_string(), ::serde_json::json!(0));
136    obj.insert("errorMessage".to_string(), ::serde_json::Value::Null);
137    ::serde_json::Value::Object(obj)
138}