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