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