crabka_protocol/opt/rustwide/workdir/generated/
UnregisterBrokerResponse.borrowed.rs1use bytes::BufMut;
4
5use crate::primitives::fixed::{get_i16, get_i32, put_i16, put_i32};
6use crate::primitives::string_bytes::{
7 compact_nullable_string_len, nullable_string_len, put_compact_nullable_string,
8 put_nullable_string,
9};
10use crate::primitives::string_bytes_borrowed::{
11 get_compact_nullable_string_borrowed, get_nullable_string_borrowed,
12};
13use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
14use crate::{DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields};
15
16pub const API_KEY: i16 = 64;
17pub const MIN_VERSION: i16 = 0;
18pub const MAX_VERSION: i16 = 0;
19pub const FLEXIBLE_MIN: i16 = 0;
20
21#[inline]
22fn is_flexible(version: i16) -> bool {
23 version >= FLEXIBLE_MIN
24}
25
26#[derive(Debug, Clone, PartialEq, Eq, Default)]
27pub struct UnregisterBrokerResponse<'a> {
28 pub throttle_time_ms: i32,
29 pub error_code: i16,
30 pub error_message: Option<&'a str>,
31 pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl UnregisterBrokerResponse<'_> {
34 pub fn to_owned(&self) -> crate::owned::unregister_broker_response::UnregisterBrokerResponse {
35 crate::owned::unregister_broker_response::UnregisterBrokerResponse {
36 throttle_time_ms: (self.throttle_time_ms),
37 error_code: (self.error_code),
38 error_message: (self.error_message).map(std::string::ToString::to_string),
39 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
40 }
41 }
42}
43impl Encode for UnregisterBrokerResponse<'_> {
44 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
45 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
46 return Err(ProtocolError::UnsupportedVersion {
47 api_key: API_KEY,
48 version,
49 });
50 }
51 let flex = is_flexible(version);
52 if version >= 0 {
53 put_i32(buf, self.throttle_time_ms);
54 }
55 if version >= 0 {
56 put_i16(buf, self.error_code);
57 }
58 if version >= 0 {
59 if flex {
60 put_compact_nullable_string(buf, self.error_message);
61 } else {
62 put_nullable_string(buf, self.error_message);
63 }
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 += if flex {
82 compact_nullable_string_len(self.error_message)
83 } else {
84 nullable_string_len(self.error_message)
85 };
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 UnregisterBrokerResponse<'de> {
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.error_message = if flex {
112 get_compact_nullable_string_borrowed(buf)?
113 } else {
114 get_nullable_string_borrowed(buf)?
115 };
116 }
117 if flex {
118 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
119 }
120 Ok(out)
121 }
122}
123#[cfg(test)]
124impl UnregisterBrokerResponse<'_> {
125 #[must_use]
126 pub fn populated(version: i16) -> Self {
127 let mut m = Self::default();
128 if version >= 0 {
129 m.throttle_time_ms = 1i32;
130 }
131 if version >= 0 {
132 m.error_code = 1i16;
133 }
134 if version >= 0 {
135 m.error_message = Some("x");
136 }
137 m
138 }
139}