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