krabka_protocol/opt/rustwide/workdir/generated/
UnregisterBrokerResponse.borrowed.rs1use bytes::BufMut;
3
4use crate::{
5 DecodeBorrow, Encode, ProtocolError, UnknownTaggedFields,
6 primitives::{
7 fixed::{get_i16, get_i32, put_i16, put_i32},
8 string_bytes::{
9 compact_nullable_string_len, nullable_string_len, put_compact_nullable_string,
10 put_nullable_string,
11 },
12 string_bytes_borrowed::{
13 get_compact_nullable_string_borrowed, get_nullable_string_borrowed,
14 },
15 },
16 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const API_KEY: i16 = 64;
19pub const MIN_VERSION: i16 = 0;
20pub const MAX_VERSION: i16 = 0;
21pub const FLEXIBLE_MIN: i16 = 0;
22#[inline]
23#[must_use]
24pub fn is_flexible(version: i16) -> bool {
25 version >= FLEXIBLE_MIN
26}
27#[derive(Debug, Clone, PartialEq, Eq)]
28pub struct UnregisterBrokerResponse<'a> {
29 pub throttle_time_ms: i32,
30 pub error_code: i16,
31 pub error_message: Option<&'a str>,
32 pub unknown_tagged_fields: UnknownTaggedFields,
33}
34impl Default for UnregisterBrokerResponse<'_> {
35 fn default() -> Self {
36 Self {
37 throttle_time_ms: 0i32,
38 error_code: 0i16,
39 error_message: Some(""),
40 unknown_tagged_fields: UnknownTaggedFields::default(),
41 }
42 }
43}
44impl UnregisterBrokerResponse<'_> {
45 #[must_use]
49 pub fn to_owned(&self) -> crate::owned::unregister_broker_response::UnregisterBrokerResponse {
50 crate::owned::unregister_broker_response::UnregisterBrokerResponse {
51 throttle_time_ms: (self.throttle_time_ms),
52 error_code: (self.error_code),
53 error_message: (self.error_message).map(std::string::ToString::to_string),
54 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
55 }
56 }
57}
58impl Encode for UnregisterBrokerResponse<'_> {
59 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
60 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
61 return Err(ProtocolError::UnsupportedVersion {
62 api_key: API_KEY,
63 version,
64 });
65 }
66 let flex = is_flexible(version);
67 if version >= 0 {
68 put_i32(buf, self.throttle_time_ms);
69 }
70 if version >= 0 {
71 put_i16(buf, self.error_code);
72 }
73 if version >= 0 {
74 if flex {
75 let () = put_compact_nullable_string(buf, self.error_message);
76 } else {
77 let () = put_nullable_string(buf, self.error_message);
78 }
79 }
80 if flex {
81 let tagged = WriteTaggedFields::new();
82 tagged.write(buf, &self.unknown_tagged_fields);
83 }
84 Ok(())
85 }
86 fn encoded_len(&self, version: i16) -> usize {
87 let flex = is_flexible(version);
88 let mut n: usize = 0;
89 if version >= 0 {
90 n += 4;
91 }
92 if version >= 0 {
93 n += 2;
94 }
95 if version >= 0 {
96 n += if flex {
97 compact_nullable_string_len(self.error_message)
98 } else {
99 nullable_string_len(self.error_message)
100 };
101 }
102 if flex {
103 let known_pairs: Vec<(u32, usize)> = Vec::new();
104 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
105 }
106 n
107 }
108}
109impl<'de> DecodeBorrow<'de> for UnregisterBrokerResponse<'de> {
110 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
111 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
112 return Err(ProtocolError::UnsupportedVersion {
113 api_key: API_KEY,
114 version,
115 });
116 }
117 let flex = is_flexible(version);
118 let mut out = Self::default();
119 if version >= 0 {
120 out.throttle_time_ms = get_i32(buf)?;
121 }
122 if version >= 0 {
123 out.error_code = get_i16(buf)?;
124 }
125 if version >= 0 {
126 out.error_message = if flex {
127 get_compact_nullable_string_borrowed(buf)?
128 } else {
129 get_nullable_string_borrowed(buf)?
130 };
131 }
132 if flex {
133 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
134 }
135 Ok(out)
136 }
137}
138#[cfg(test)]
139impl UnregisterBrokerResponse<'_> {
140 #[must_use]
141 pub fn populated(version: i16) -> Self {
142 let mut m = Self::default();
143 if version >= 0 {
144 m.throttle_time_ms = 1i32;
145 }
146 if version >= 0 {
147 m.error_code = 1i16;
148 }
149 if version >= 0 {
150 m.error_message = Some("x");
151 }
152 m
153 }
154}