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