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::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
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 { version >= FLEXIBLE_MIN }
16
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct BrokerRegistrationResponse {
19 pub throttle_time_ms: i32,
20 pub error_code: i16,
21 pub broker_epoch: i64,
22 pub unknown_tagged_fields: UnknownTaggedFields,
23}
24
25impl Default for BrokerRegistrationResponse {
26 fn default() -> Self {
27 Self {
28 throttle_time_ms: 0i32,
29 error_code: 0i16,
30 broker_epoch: -1i64,
31 unknown_tagged_fields: Default::default(),
32 }
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 { api_key: API_KEY, version });
40 }
41 let flex = is_flexible(version);
42 if version >= 0 { put_i32(buf, self.throttle_time_ms) }
43 if version >= 0 { put_i16(buf, self.error_code) }
44 if version >= 0 { put_i64(buf, self.broker_epoch) }
45 if flex {
46 let tagged = WriteTaggedFields::new();
47 tagged.write(buf, &self.unknown_tagged_fields);
48 }
49 Ok(())
50 }
51 fn encoded_len(&self, version: i16) -> usize {
52 let flex = is_flexible(version);
53 let mut n: usize = 0;
54 if version >= 0 { n += 4; }
55 if version >= 0 { n += 2; }
56 if version >= 0 { n += 8; }
57 if flex {
58 let known_pairs: Vec<(u32, usize)> = Vec::new();
59 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
60 }
61 n
62 }
63}
64
65impl<'de> Decode<'de> for BrokerRegistrationResponse {
66 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
67 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
68 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
69 }
70 let flex = is_flexible(version);
71 let mut out = Self::default();
72 if version >= 0 { out.throttle_time_ms = get_i32(buf)?; }
73 if version >= 0 { out.error_code = get_i16(buf)?; }
74 if version >= 0 { out.broker_epoch = get_i64(buf)?; }
75 if flex {
76 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
77 Ok(false)
78 })?;
79 }
80 Ok(out)
81 }
82}
83
84#[must_use]
87#[allow(unused_comparisons)]
88pub fn default_json(version: i16) -> ::serde_json::Value {
89 let mut obj = ::serde_json::Map::new();
90 obj.insert("throttleTimeMs".to_string(), ::serde_json::json!(0));
91 obj.insert("errorCode".to_string(), ::serde_json::json!(0));
92 obj.insert("brokerEpoch".to_string(), ::serde_json::json!(-1));
93 ::serde_json::Value::Object(obj)
94}