krabka_protocol/opt/rustwide/workdir/generated/
BrokerRegistrationResponse.borrowed.rs1use bytes::BufMut;
3
4use crate::{
5 DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6 owned::broker_registration_response,
7 primitives::fixed::{get_i16, get_i32, get_i64, put_i16, put_i32, put_i64},
8 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
9};
10pub const API_KEY: i16 = 62;
11pub const MIN_VERSION: i16 = 0;
12pub const MAX_VERSION: i16 = 4;
13pub const FLEXIBLE_MIN: i16 = 0;
14#[inline]
15#[must_use]
16pub fn is_flexible(version: i16) -> bool {
17 version >= FLEXIBLE_MIN
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: UnknownTaggedFields::default(),
33 }
34 }
35}
36impl BrokerRegistrationResponse {
37 #[must_use]
38 pub fn to_owned(&self) -> broker_registration_response::BrokerRegistrationResponse {
39 broker_registration_response::BrokerRegistrationResponse {
40 throttle_time_ms: (self.throttle_time_ms),
41 error_code: (self.error_code),
42 broker_epoch: (self.broker_epoch),
43 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
44 }
45 }
46}
47impl Encode for BrokerRegistrationResponse {
48 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
49 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
50 return Err(ProtocolError::UnsupportedVersion {
51 api_key: API_KEY,
52 version,
53 });
54 }
55 let flex = is_flexible(version);
56 if version >= 0 {
57 put_i32(buf, self.throttle_time_ms);
58 }
59 if version >= 0 {
60 put_i16(buf, self.error_code);
61 }
62 if version >= 0 {
63 put_i64(buf, self.broker_epoch);
64 }
65 if flex {
66 let tagged = WriteTaggedFields::new();
67 tagged.write(buf, &self.unknown_tagged_fields)?;
68 }
69 Ok(())
70 }
71 fn encoded_len(&self, version: i16) -> usize {
72 let flex = is_flexible(version);
73 let mut n: usize = 0;
74 if version >= 0 {
75 n += 4;
76 }
77 if version >= 0 {
78 n += 2;
79 }
80 if version >= 0 {
81 n += 8;
82 }
83 if flex {
84 let known_pairs: Vec<(u32, usize)> = Vec::new();
85 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
86 }
87 n
88 }
89}
90impl<'de> DecodeBorrow<'de> for BrokerRegistrationResponse {
91 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
92 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
93 return Err(ProtocolError::UnsupportedVersion {
94 api_key: API_KEY,
95 version,
96 });
97 }
98 let flex = is_flexible(version);
99 let mut out = Self::default();
100 if version >= 0 {
101 out.throttle_time_ms = get_i32(buf)?;
102 }
103 if version >= 0 {
104 out.error_code = get_i16(buf)?;
105 }
106 if version >= 0 {
107 out.broker_epoch = get_i64(buf)?;
108 }
109 if flex {
110 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
111 }
112 Ok(out)
113 }
114}
115#[cfg(test)]
116impl BrokerRegistrationResponse {
117 #[must_use]
118 pub fn populated(version: i16) -> Self {
119 let mut m = Self::default();
120 if version >= 0 {
121 m.throttle_time_ms = 1i32;
122 }
123 if version >= 0 {
124 m.error_code = 1i16;
125 }
126 if version >= 0 {
127 m.broker_epoch = 1i64;
128 }
129 m
130 }
131}