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