krabka_protocol/opt/rustwide/workdir/generated/
DescribeLogDirsRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::{
6 Decode, Encode, ProtocolError, UnknownTaggedFields,
7 primitives::{
8 array::{
9 array_len_prefix_len, get_array_len, get_nullable_array_len,
10 nullable_array_len_prefix_len, put_array_len, put_nullable_array_len,
11 },
12 fixed::{get_i32, put_i32},
13 string_bytes::{
14 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string,
15 put_string, string_len,
16 },
17 },
18 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
19};
20pub const API_KEY: i16 = 35;
21pub const MIN_VERSION: i16 = 1;
22pub const MAX_VERSION: i16 = 5;
23pub const LATEST_STABLE_VERSION: i16 = 5;
24pub const FLEXIBLE_MIN: i16 = 2;
25#[inline]
26#[must_use]
27pub fn is_flexible(version: i16) -> bool {
28 version >= FLEXIBLE_MIN
29}
30#[derive(Debug, Clone, PartialEq, Eq)]
31pub struct DescribeLogDirsRequest {
32 pub topics: Option<Vec<DescribableLogDirTopic>>,
33 pub unknown_tagged_fields: UnknownTaggedFields,
34}
35impl Default for DescribeLogDirsRequest {
36 fn default() -> Self {
37 Self {
38 topics: Some(Vec::new()),
39 unknown_tagged_fields: UnknownTaggedFields::default(),
40 }
41 }
42}
43impl Encode for DescribeLogDirsRequest {
44 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
45 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
46 return Err(ProtocolError::UnsupportedVersion {
47 api_key: API_KEY,
48 version,
49 });
50 }
51 let flex = is_flexible(version);
52 if version >= 0 {
53 {
54 let len = (self.topics).as_ref().map(Vec::len);
55 put_nullable_array_len(buf, len, flex)?;
56 if let Some(v) = &self.topics {
57 for it in v {
58 it.encode(buf, version)?;
59 }
60 }
61 }
62 }
63 if flex {
64 let tagged = WriteTaggedFields::new();
65 tagged.write(buf, &self.unknown_tagged_fields)?;
66 }
67 Ok(())
68 }
69 fn encoded_len(&self, version: i16) -> usize {
70 let flex = is_flexible(version);
71 let mut n: usize = 0;
72 if version >= 0 {
73 n += {
74 let opt: Option<&Vec<_>> = (self.topics).as_ref();
75 let prefix = nullable_array_len_prefix_len(opt.map(Vec::len), flex);
76 let body: usize =
77 opt.map_or(0, |v| v.iter().map(|it| it.encoded_len(version)).sum());
78 prefix + body
79 };
80 }
81 if flex {
82 let known_pairs: Vec<(u32, usize)> = Vec::new();
83 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
84 }
85 n
86 }
87}
88impl Decode<'_> for DescribeLogDirsRequest {
89 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
90 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
91 return Err(ProtocolError::UnsupportedVersion {
92 api_key: API_KEY,
93 version,
94 });
95 }
96 let flex = is_flexible(version);
97 let mut out = Self::default();
98 if version >= 0 {
99 out.topics = {
100 let opt = get_nullable_array_len(buf, flex)?;
101 match opt {
102 None => None,
103 Some(n) => {
104 let mut v = Vec::with_capacity(n);
105 for _ in 0..n {
106 v.push(DescribableLogDirTopic::decode(buf, version)?);
107 }
108 Some(v)
109 }
110 }
111 };
112 }
113 if flex {
114 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
115 }
116 Ok(out)
117 }
118}
119#[cfg(test)]
120impl DescribeLogDirsRequest {
121 #[must_use]
122 pub fn populated(version: i16) -> Self {
123 let mut m = Self::default();
124 if version >= 0 {
125 m.topics = Some(vec![DescribableLogDirTopic::populated(version)]);
126 }
127 m
128 }
129}
130#[derive(Debug, Clone, PartialEq, Eq, Default)]
131pub struct DescribableLogDirTopic {
132 pub topic: String,
133 pub partitions: Vec<i32>,
134 pub unknown_tagged_fields: UnknownTaggedFields,
135}
136impl Encode for DescribableLogDirTopic {
137 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
138 let flex = version >= 2;
139 if version >= 0 {
140 if flex {
141 put_compact_string(buf, &self.topic)?;
142 } else {
143 put_string(buf, &self.topic)?;
144 }
145 }
146 if version >= 0 {
147 {
148 put_array_len(buf, (self.partitions).len(), flex)?;
149 for it in &self.partitions {
150 put_i32(buf, *it);
151 }
152 }
153 }
154 if flex {
155 let tagged = WriteTaggedFields::new();
156 tagged.write(buf, &self.unknown_tagged_fields)?;
157 }
158 Ok(())
159 }
160 fn encoded_len(&self, version: i16) -> usize {
161 let flex = version >= 2;
162 let mut n: usize = 0;
163 if version >= 0 {
164 n += if flex {
165 compact_string_len(&self.topic)
166 } else {
167 string_len(&self.topic)
168 };
169 }
170 if version >= 0 {
171 n += {
172 let prefix = 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 = 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_owned();
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_owned(), ::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}