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