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