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