krabka_protocol/opt/rustwide/workdir/generated/
OffsetCommitResponse.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_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
12 put_string, string_len,
13 },
14 uuid::{Uuid, get_uuid, put_uuid},
15 },
16 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
17};
18pub const API_KEY: i16 = 8;
19pub const MIN_VERSION: i16 = 2;
20pub const MAX_VERSION: i16 = 10;
21pub const FLEXIBLE_MIN: i16 = 8;
22#[inline]
23#[must_use]
24pub fn is_flexible(version: i16) -> bool {
25 version >= FLEXIBLE_MIN
26}
27#[derive(Debug, Clone, PartialEq, Eq, Default)]
28pub struct OffsetCommitResponse {
29 pub throttle_time_ms: i32,
30 pub topics: Vec<OffsetCommitResponseTopic>,
31 pub unknown_tagged_fields: UnknownTaggedFields,
32}
33impl Encode for OffsetCommitResponse {
34 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
35 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
36 return Err(ProtocolError::UnsupportedVersion {
37 api_key: API_KEY,
38 version,
39 });
40 }
41 let flex = is_flexible(version);
42 if version >= 3 {
43 put_i32(buf, self.throttle_time_ms);
44 }
45 if version >= 0 {
46 {
47 put_array_len(buf, (self.topics).len(), flex)?;
48 for it in &self.topics {
49 it.encode(buf, version)?;
50 }
51 }
52 }
53 if flex {
54 let tagged = WriteTaggedFields::new();
55 tagged.write(buf, &self.unknown_tagged_fields)?;
56 }
57 Ok(())
58 }
59 fn encoded_len(&self, version: i16) -> usize {
60 let flex = is_flexible(version);
61 let mut n: usize = 0;
62 if version >= 3 {
63 n += 4;
64 }
65 if version >= 0 {
66 n += {
67 let prefix = array_len_prefix_len((self.topics).len(), flex);
68 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
69 prefix + body
70 };
71 }
72 if flex {
73 let known_pairs: Vec<(u32, usize)> = Vec::new();
74 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
75 }
76 n
77 }
78}
79impl Decode<'_> for OffsetCommitResponse {
80 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
81 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
82 return Err(ProtocolError::UnsupportedVersion {
83 api_key: API_KEY,
84 version,
85 });
86 }
87 let flex = is_flexible(version);
88 let mut out = Self::default();
89 if version >= 3 {
90 out.throttle_time_ms = get_i32(buf)?;
91 }
92 if version >= 0 {
93 out.topics = {
94 let n = get_array_len(buf, flex)?;
95 let mut v = Vec::with_capacity(n);
96 for _ in 0..n {
97 v.push(OffsetCommitResponseTopic::decode(buf, version)?);
98 }
99 v
100 };
101 }
102 if flex {
103 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
104 }
105 Ok(out)
106 }
107}
108#[cfg(test)]
109impl OffsetCommitResponse {
110 #[must_use]
111 pub fn populated(version: i16) -> Self {
112 let mut m = Self::default();
113 if version >= 3 {
114 m.throttle_time_ms = 1i32;
115 }
116 if version >= 0 {
117 m.topics = vec![OffsetCommitResponseTopic::populated(version)];
118 }
119 m
120 }
121}
122#[derive(Debug, Clone, PartialEq, Eq, Default)]
123pub struct OffsetCommitResponseTopic {
124 pub name: String,
125 pub topic_id: Uuid,
126 pub partitions: Vec<OffsetCommitResponsePartition>,
127 pub unknown_tagged_fields: UnknownTaggedFields,
128}
129impl Encode for OffsetCommitResponseTopic {
130 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
131 let flex = version >= 8;
132 if (0..=9).contains(&version) {
133 if flex {
134 put_compact_string(buf, &self.name)?;
135 } else {
136 put_string(buf, &self.name)?;
137 }
138 }
139 if version >= 10 {
140 put_uuid(buf, self.topic_id);
141 }
142 if version >= 0 {
143 {
144 put_array_len(buf, (self.partitions).len(), flex)?;
145 for it in &self.partitions {
146 it.encode(buf, version)?;
147 }
148 }
149 }
150 if flex {
151 let tagged = WriteTaggedFields::new();
152 tagged.write(buf, &self.unknown_tagged_fields)?;
153 }
154 Ok(())
155 }
156 fn encoded_len(&self, version: i16) -> usize {
157 let flex = version >= 8;
158 let mut n: usize = 0;
159 if (0..=9).contains(&version) {
160 n += if flex {
161 compact_string_len(&self.name)
162 } else {
163 string_len(&self.name)
164 };
165 }
166 if version >= 10 {
167 n += 16;
168 }
169 if version >= 0 {
170 n += {
171 let prefix = array_len_prefix_len((self.partitions).len(), flex);
172 let body: usize = (self.partitions)
173 .iter()
174 .map(|it| it.encoded_len(version))
175 .sum();
176 prefix + body
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 OffsetCommitResponseTopic {
187 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
188 let flex = version >= 8;
189 let mut out = Self::default();
190 if (0..=9).contains(&version) {
191 out.name = if flex {
192 get_compact_string_owned(buf)?
193 } else {
194 get_string_owned(buf)?
195 };
196 }
197 if version >= 10 {
198 out.topic_id = get_uuid(buf)?;
199 }
200 if version >= 0 {
201 out.partitions = {
202 let n = get_array_len(buf, flex)?;
203 let mut v = Vec::with_capacity(n);
204 for _ in 0..n {
205 v.push(OffsetCommitResponsePartition::decode(buf, version)?);
206 }
207 v
208 };
209 }
210 if flex {
211 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
212 }
213 Ok(out)
214 }
215}
216#[cfg(test)]
217impl OffsetCommitResponseTopic {
218 #[must_use]
219 pub fn populated(version: i16) -> Self {
220 let mut m = Self::default();
221 if (0..=9).contains(&version) {
222 m.name = "x".to_owned();
223 }
224 if version >= 10 {
225 m.topic_id = Uuid([1u8; 16]);
226 }
227 if version >= 0 {
228 m.partitions = vec![OffsetCommitResponsePartition::populated(version)];
229 }
230 m
231 }
232}
233#[derive(Debug, Clone, PartialEq, Eq, Default)]
234pub struct OffsetCommitResponsePartition {
235 pub partition_index: i32,
236 pub error_code: i16,
237 pub unknown_tagged_fields: UnknownTaggedFields,
238}
239impl Encode for OffsetCommitResponsePartition {
240 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
241 let flex = version >= 8;
242 if version >= 0 {
243 put_i32(buf, self.partition_index);
244 }
245 if version >= 0 {
246 put_i16(buf, self.error_code);
247 }
248 if flex {
249 let tagged = WriteTaggedFields::new();
250 tagged.write(buf, &self.unknown_tagged_fields)?;
251 }
252 Ok(())
253 }
254 fn encoded_len(&self, version: i16) -> usize {
255 let flex = version >= 8;
256 let mut n: usize = 0;
257 if version >= 0 {
258 n += 4;
259 }
260 if version >= 0 {
261 n += 2;
262 }
263 if flex {
264 let known_pairs: Vec<(u32, usize)> = Vec::new();
265 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
266 }
267 n
268 }
269}
270impl Decode<'_> for OffsetCommitResponsePartition {
271 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
272 let flex = version >= 8;
273 let mut out = Self::default();
274 if version >= 0 {
275 out.partition_index = get_i32(buf)?;
276 }
277 if version >= 0 {
278 out.error_code = get_i16(buf)?;
279 }
280 if flex {
281 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
282 }
283 Ok(out)
284 }
285}
286#[cfg(test)]
287impl OffsetCommitResponsePartition {
288 #[must_use]
289 pub fn populated(version: i16) -> Self {
290 let mut m = Self::default();
291 if version >= 0 {
292 m.partition_index = 1i32;
293 }
294 if version >= 0 {
295 m.error_code = 1i16;
296 }
297 m
298 }
299}
300#[must_use]
303#[allow(unused_comparisons)]
304pub fn default_json(version: i16) -> ::serde_json::Value {
305 let mut obj = ::serde_json::Map::new();
306 if version >= 3 {
307 obj.insert("throttleTimeMs".to_owned(), ::serde_json::json!(0));
308 }
309 obj.insert("topics".to_owned(), ::serde_json::Value::Array(vec![]));
310 ::serde_json::Value::Object(obj)
311}