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