krabka_protocol/opt/rustwide/workdir/generated/
CreatePartitionsResponse.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, compact_string_len, nullable_string_len,
10 put_compact_nullable_string, put_compact_string, put_nullable_string, put_string,
11 string_len,
12 },
13 string_bytes_borrowed::{
14 get_compact_nullable_string_borrowed, get_compact_string_borrowed,
15 get_nullable_string_borrowed, get_string_borrowed,
16 },
17 },
18 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
19};
20pub const API_KEY: i16 = 37;
21pub const MIN_VERSION: i16 = 0;
22pub const MAX_VERSION: i16 = 3;
23pub const FLEXIBLE_MIN: i16 = 2;
24#[inline]
25#[must_use]
26pub fn is_flexible(version: i16) -> bool {
27 version >= FLEXIBLE_MIN
28}
29#[derive(Debug, Clone, PartialEq, Eq, Default)]
30pub struct CreatePartitionsResponse<'a> {
31 pub throttle_time_ms: i32,
32 pub results: Vec<CreatePartitionsTopicResult<'a>>,
33 pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl CreatePartitionsResponse<'_> {
36 #[must_use]
40 pub fn to_owned(&self) -> crate::owned::create_partitions_response::CreatePartitionsResponse {
41 crate::owned::create_partitions_response::CreatePartitionsResponse {
42 throttle_time_ms: (self.throttle_time_ms),
43 results: (self.results)
44 .iter()
45 .map(CreatePartitionsTopicResult::to_owned)
46 .collect(),
47 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
48 }
49 }
50}
51impl Encode for CreatePartitionsResponse<'_> {
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 {
65 crate::primitives::array::put_array_len(buf, (self.results).len(), flex);
66 for it in &self.results {
67 it.encode(buf, version)?;
68 }
69 };
70 }
71 if flex {
72 let tagged = WriteTaggedFields::new();
73 tagged.write(buf, &self.unknown_tagged_fields);
74 }
75 Ok(())
76 }
77 fn encoded_len(&self, version: i16) -> usize {
78 let flex = is_flexible(version);
79 let mut n: usize = 0;
80 if version >= 0 {
81 n += 4;
82 }
83 if version >= 0 {
84 n += {
85 let prefix =
86 crate::primitives::array::array_len_prefix_len((self.results).len(), flex);
87 let body: usize = (self.results)
88 .iter()
89 .map(|it| it.encoded_len(version))
90 .sum();
91 prefix + body
92 };
93 }
94 if flex {
95 let known_pairs: Vec<(u32, usize)> = Vec::new();
96 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
97 }
98 n
99 }
100}
101impl<'de> DecodeBorrow<'de> for CreatePartitionsResponse<'de> {
102 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
103 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
104 return Err(ProtocolError::UnsupportedVersion {
105 api_key: API_KEY,
106 version,
107 });
108 }
109 let flex = is_flexible(version);
110 let mut out = Self::default();
111 if version >= 0 {
112 out.throttle_time_ms = get_i32(buf)?;
113 }
114 if version >= 0 {
115 out.results = {
116 let n = crate::primitives::array::get_array_len(buf, flex)?;
117 let mut v = Vec::with_capacity(n);
118 for _ in 0..n {
119 v.push(CreatePartitionsTopicResult::decode_borrow(buf, version)?);
120 }
121 v
122 };
123 }
124 if flex {
125 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
126 }
127 Ok(out)
128 }
129}
130#[cfg(test)]
131impl CreatePartitionsResponse<'_> {
132 #[must_use]
133 pub fn populated(version: i16) -> Self {
134 let mut m = Self::default();
135 if version >= 0 {
136 m.throttle_time_ms = 1i32;
137 }
138 if version >= 0 {
139 m.results = vec![CreatePartitionsTopicResult::populated(version)];
140 }
141 m
142 }
143}
144#[derive(Debug, Clone, PartialEq, Eq, Default)]
145pub struct CreatePartitionsTopicResult<'a> {
146 pub name: &'a str,
147 pub error_code: i16,
148 pub error_message: Option<&'a str>,
149 pub unknown_tagged_fields: UnknownTaggedFields,
150}
151impl CreatePartitionsTopicResult<'_> {
152 #[must_use]
156 pub fn to_owned(
157 &self,
158 ) -> crate::owned::create_partitions_response::CreatePartitionsTopicResult {
159 crate::owned::create_partitions_response::CreatePartitionsTopicResult {
160 name: (self.name).to_string(),
161 error_code: (self.error_code),
162 error_message: (self.error_message).map(std::string::ToString::to_string),
163 unknown_tagged_fields: self.unknown_tagged_fields.clone(),
164 }
165 }
166}
167impl Encode for CreatePartitionsTopicResult<'_> {
168 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
169 let flex = version >= 2;
170 if version >= 0 {
171 if flex {
172 let () = put_compact_string(buf, self.name);
173 } else {
174 let () = put_string(buf, self.name);
175 }
176 }
177 if version >= 0 {
178 put_i16(buf, self.error_code);
179 }
180 if version >= 0 {
181 if flex {
182 let () = put_compact_nullable_string(buf, self.error_message);
183 } else {
184 let () = put_nullable_string(buf, self.error_message);
185 }
186 }
187 if flex {
188 let tagged = WriteTaggedFields::new();
189 tagged.write(buf, &self.unknown_tagged_fields);
190 }
191 Ok(())
192 }
193 fn encoded_len(&self, version: i16) -> usize {
194 let flex = version >= 2;
195 let mut n: usize = 0;
196 if version >= 0 {
197 n += if flex {
198 compact_string_len(self.name)
199 } else {
200 string_len(self.name)
201 };
202 }
203 if version >= 0 {
204 n += 2;
205 }
206 if version >= 0 {
207 n += if flex {
208 compact_nullable_string_len(self.error_message)
209 } else {
210 nullable_string_len(self.error_message)
211 };
212 }
213 if flex {
214 let known_pairs: Vec<(u32, usize)> = Vec::new();
215 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
216 }
217 n
218 }
219}
220impl<'de> DecodeBorrow<'de> for CreatePartitionsTopicResult<'de> {
221 fn decode_borrow(buf: &mut &'de [u8], version: i16) -> Result<Self, ProtocolError> {
222 let flex = version >= 2;
223 let mut out = Self::default();
224 if version >= 0 {
225 out.name = if flex {
226 get_compact_string_borrowed(buf)?
227 } else {
228 get_string_borrowed(buf)?
229 };
230 }
231 if version >= 0 {
232 out.error_code = get_i16(buf)?;
233 }
234 if version >= 0 {
235 out.error_message = if flex {
236 get_compact_nullable_string_borrowed(buf)?
237 } else {
238 get_nullable_string_borrowed(buf)?
239 };
240 }
241 if flex {
242 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
243 }
244 Ok(out)
245 }
246}
247#[cfg(test)]
248impl CreatePartitionsTopicResult<'_> {
249 #[must_use]
250 pub fn populated(version: i16) -> Self {
251 let mut m = Self::default();
252 if version >= 0 {
253 m.name = "x";
254 }
255 if version >= 0 {
256 m.error_code = 1i16;
257 }
258 if version >= 0 {
259 m.error_message = Some("x");
260 }
261 m
262 }
263}