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