odradek_protocol/messages/
delete_topics_response.rs1#![allow(
6 clippy::field_reassign_with_default,
7 clippy::nonminimal_bool,
8 clippy::derivable_impls,
9 clippy::borrow_deref_ref,
10 clippy::double_parens,
11 unused_parens
12)]
13
14use bytes::{Buf, BufMut};
15
16use crate::budget::{Budget, Limits};
17#[allow(unused_imports)]
18use crate::error::{DecodeError, EncodeError};
19use crate::wire::{self, RawTaggedField};
20
21pub fn is_flexible(version: i16) -> bool {
23 let _ = version;
24 version >= 4
25}
26
27#[derive(Debug, Clone, PartialEq)]
29#[non_exhaustive]
30pub struct DeleteTopicsResponse {
31 pub throttle_time_ms: i32,
33 pub responses: Vec<DeletableTopicResult>,
35 pub unknown_tagged_fields: Vec<RawTaggedField>,
37}
38
39impl Default for DeleteTopicsResponse {
40 fn default() -> Self {
41 Self {
42 throttle_time_ms: 0,
43 responses: Vec::new(),
44 unknown_tagged_fields: Vec::new(),
45 }
46 }
47}
48
49impl DeleteTopicsResponse {
50 pub const API_KEY: i16 = 20;
52 pub const MIN_VERSION: i16 = 1;
54 pub const MAX_VERSION: i16 = 6;
56
57 pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
59 buf.put_i32(self.throttle_time_ms);
60 if is_flexible(version) {
61 wire::put_compact_array_len(buf, Some(self.responses.len()));
62 } else {
63 wire::put_array_len(buf, Some(self.responses.len()))?;
64 }
65 for item in &self.responses {
66 item.encode(buf, version)?;
67 }
68 if is_flexible(version) {
69 wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
70 }
71 Ok(())
72 }
73
74 pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
77 Self::decode_with_limits(buf, version, Limits::default())
78 }
79
80 pub fn decode_with_limits(
82 buf: &mut impl Buf,
83 version: i16,
84 limits: Limits,
85 ) -> Result<Self, DecodeError> {
86 let mut budget = limits.budget(buf.remaining());
87 Self::decode_with_budget(buf, version, &mut budget)
88 }
89
90 pub fn decode_with_budget(
92 buf: &mut impl Buf,
93 version: i16,
94 budget: &mut Budget,
95 ) -> Result<Self, DecodeError> {
96 let mut this = Self::default();
97 this.throttle_time_ms = wire::get_i32(buf)?;
98 this.responses = {
99 let len = if is_flexible(version) {
100 wire::get_compact_array_len(buf)?
101 } else {
102 wire::get_array_len(buf)?
103 };
104 match len {
105 None => return Err(DecodeError::InvalidLength(-1)),
106 Some(n) => {
107 let mut items = Vec::new();
108 for _ in 0..n {
109 let mark = buf.remaining();
110 let item = DeletableTopicResult::decode_with_budget(buf, version, budget)?;
111 budget.progress(mark, buf.remaining())?;
112 budget.push(&mut items, item)?;
113 }
114 items
115 }
116 }
117 };
118 if is_flexible(version) {
119 this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
120 }
121 Ok(this)
122 }
123}
124
125impl crate::Message for DeleteTopicsResponse {
126 const API_KEY: i16 = 20;
127 const MIN_VERSION: i16 = 1;
128 const MAX_VERSION: i16 = 6;
129
130 fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
131 DeleteTopicsResponse::encode(self, buf, version)
132 }
133 fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
134 DeleteTopicsResponse::decode(buf, version)
135 }
136 fn decode_with_limits(
137 buf: &mut impl Buf,
138 version: i16,
139 limits: Limits,
140 ) -> Result<Self, DecodeError> {
141 DeleteTopicsResponse::decode_with_limits(buf, version, limits)
142 }
143 fn throttle_time_ms(&self) -> Option<i32> {
144 Some(self.throttle_time_ms)
145 }
146}
147
148#[derive(Debug, Clone, PartialEq)]
150#[non_exhaustive]
151pub struct DeletableTopicResult {
152 pub name: Option<String>,
154 pub topic_id: [u8; 16],
156 pub error_code: i16,
158 pub error_message: Option<String>,
160 pub unknown_tagged_fields: Vec<RawTaggedField>,
162}
163
164impl Default for DeletableTopicResult {
165 fn default() -> Self {
166 Self {
167 name: Some(String::new()),
168 topic_id: [0u8; 16],
169 error_code: 0,
170 error_message: None,
171 unknown_tagged_fields: Vec::new(),
172 }
173 }
174}
175
176impl DeletableTopicResult {
177 pub fn encode(&self, buf: &mut impl BufMut, version: i16) -> Result<(), EncodeError> {
179 if self.name.is_none() && !(version >= 6) {
180 return Err(EncodeError::NullField("Name"));
181 }
182 if is_flexible(version) {
183 wire::put_compact_nullable_string(buf, self.name.as_deref());
184 } else {
185 wire::put_nullable_string(buf, self.name.as_deref())?;
186 }
187 if version >= 6 {
188 wire::put_uuid(buf, self.topic_id);
189 }
190 buf.put_i16(self.error_code);
191 if version >= 5 {
192 if is_flexible(version) {
193 wire::put_compact_nullable_string(buf, self.error_message.as_deref());
194 } else {
195 wire::put_nullable_string(buf, self.error_message.as_deref())?;
196 }
197 }
198 if is_flexible(version) {
199 wire::put_tagged_fields(buf, &self.unknown_tagged_fields);
200 }
201 Ok(())
202 }
203
204 pub fn decode(buf: &mut impl Buf, version: i16) -> Result<Self, DecodeError> {
207 Self::decode_with_limits(buf, version, Limits::default())
208 }
209
210 pub fn decode_with_limits(
212 buf: &mut impl Buf,
213 version: i16,
214 limits: Limits,
215 ) -> Result<Self, DecodeError> {
216 let mut budget = limits.budget(buf.remaining());
217 Self::decode_with_budget(buf, version, &mut budget)
218 }
219
220 pub fn decode_with_budget(
222 buf: &mut impl Buf,
223 version: i16,
224 budget: &mut Budget,
225 ) -> Result<Self, DecodeError> {
226 let mut this = Self::default();
227 this.name = {
228 let raw = if is_flexible(version) {
229 wire::get_compact_nullable_string(buf)?
230 } else {
231 wire::get_nullable_string(buf)?
232 };
233 if raw.is_none() && !(version >= 6) {
234 return Err(DecodeError::InvalidLength(-1));
235 }
236 raw
237 };
238 if version >= 6 {
239 this.topic_id = wire::get_uuid(buf)?;
240 }
241 this.error_code = wire::get_i16(buf)?;
242 if version >= 5 {
243 this.error_message = if is_flexible(version) {
244 wire::get_compact_nullable_string(buf)?
245 } else {
246 wire::get_nullable_string(buf)?
247 };
248 }
249 if is_flexible(version) {
250 this.unknown_tagged_fields = wire::get_tagged_fields_with_budget(buf, budget)?;
251 }
252 Ok(this)
253 }
254}