krabka_protocol/opt/rustwide/workdir/generated/
DescribeProducersRequest.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_i32, 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 },
15 tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len},
16};
17pub const API_KEY: i16 = 61;
18pub const MIN_VERSION: i16 = 0;
19pub const MAX_VERSION: i16 = 0;
20pub const LATEST_STABLE_VERSION: i16 = 0;
21pub const FLEXIBLE_MIN: i16 = 0;
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 DescribeProducersRequest {
29 pub topics: Vec<TopicRequest>,
30 pub unknown_tagged_fields: UnknownTaggedFields,
31}
32impl Encode for DescribeProducersRequest {
33 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
34 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
35 return Err(ProtocolError::UnsupportedVersion {
36 api_key: API_KEY,
37 version,
38 });
39 }
40 let flex = is_flexible(version);
41 if version >= 0 {
42 {
43 put_array_len(buf, (self.topics).len(), flex)?;
44 for it in &self.topics {
45 it.encode(buf, version)?;
46 }
47 }
48 }
49 if flex {
50 let tagged = WriteTaggedFields::new();
51 tagged.write(buf, &self.unknown_tagged_fields)?;
52 }
53 Ok(())
54 }
55 fn encoded_len(&self, version: i16) -> usize {
56 let flex = is_flexible(version);
57 let mut n: usize = 0;
58 if version >= 0 {
59 n += {
60 let prefix = array_len_prefix_len((self.topics).len(), flex);
61 let body: usize = (self.topics).iter().map(|it| it.encoded_len(version)).sum();
62 prefix + body
63 };
64 }
65 if flex {
66 let known_pairs: Vec<(u32, usize)> = Vec::new();
67 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
68 }
69 n
70 }
71}
72impl Decode<'_> for DescribeProducersRequest {
73 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
74 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
75 return Err(ProtocolError::UnsupportedVersion {
76 api_key: API_KEY,
77 version,
78 });
79 }
80 let flex = is_flexible(version);
81 let mut out = Self::default();
82 if version >= 0 {
83 out.topics = {
84 let n = get_array_len(buf, flex)?;
85 let mut v = Vec::with_capacity(n);
86 for _ in 0..n {
87 v.push(TopicRequest::decode(buf, version)?);
88 }
89 v
90 };
91 }
92 if flex {
93 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
94 }
95 Ok(out)
96 }
97}
98#[cfg(test)]
99impl DescribeProducersRequest {
100 #[must_use]
101 pub fn populated(version: i16) -> Self {
102 let mut m = Self::default();
103 if version >= 0 {
104 m.topics = vec![TopicRequest::populated(version)];
105 }
106 m
107 }
108}
109#[derive(Debug, Clone, PartialEq, Eq, Default)]
110pub struct TopicRequest {
111 pub name: String,
112 pub partition_indexes: Vec<i32>,
113 pub unknown_tagged_fields: UnknownTaggedFields,
114}
115impl Encode for TopicRequest {
116 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
117 let flex = version >= 0;
118 if version >= 0 {
119 if flex {
120 put_compact_string(buf, &self.name)?;
121 } else {
122 put_string(buf, &self.name)?;
123 }
124 }
125 if version >= 0 {
126 {
127 put_array_len(buf, (self.partition_indexes).len(), flex)?;
128 for it in &self.partition_indexes {
129 put_i32(buf, *it);
130 }
131 }
132 }
133 if flex {
134 let tagged = WriteTaggedFields::new();
135 tagged.write(buf, &self.unknown_tagged_fields)?;
136 }
137 Ok(())
138 }
139 fn encoded_len(&self, version: i16) -> usize {
140 let flex = version >= 0;
141 let mut n: usize = 0;
142 if version >= 0 {
143 n += if flex {
144 compact_string_len(&self.name)
145 } else {
146 string_len(&self.name)
147 };
148 }
149 if version >= 0 {
150 n += {
151 let prefix = array_len_prefix_len((self.partition_indexes).len(), flex);
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 = 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_owned();
197 }
198 if version >= 0 {
199 m.partition_indexes = vec![1i32];
200 }
201 m
202 }
203}
204#[must_use]
207#[allow(unused_comparisons)]
208pub fn default_json(_version: i16) -> ::serde_json::Value {
209 let mut obj = ::serde_json::Map::new();
210 obj.insert("topics".to_owned(), ::serde_json::Value::Array(vec![]));
211 ::serde_json::Value::Object(obj)
212}
213impl crate::ProtocolRequest for DescribeProducersRequest {
214 const API_KEY: i16 = API_KEY;
215 const MIN_VERSION: i16 = MIN_VERSION;
216 const MAX_VERSION: i16 = MAX_VERSION;
217 const LATEST_STABLE_VERSION: i16 = LATEST_STABLE_VERSION;
218 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
219 type Response = super::describe_producers_response::DescribeProducersResponse;
220}