crabka_protocol/opt/rustwide/workdir/generated/
DescribeTopicPartitionsRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i32, get_i8, put_i32};
6use crate::primitives::string_bytes::{
7 compact_string_len, get_compact_string_owned, get_string_owned,
8 put_compact_string, put_string, string_len,
9};
10use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
11use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
12
13pub const API_KEY: i16 = 75;
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 { version >= FLEXIBLE_MIN }
20
21#[derive(Debug, Clone, PartialEq, Eq)]
22pub struct DescribeTopicPartitionsRequest {
23 pub topics: Vec<TopicRequest>,
24 pub response_partition_limit: i32,
25 pub cursor: Option<Cursor>,
26 pub unknown_tagged_fields: UnknownTaggedFields,
27}
28
29impl Default for DescribeTopicPartitionsRequest {
30 fn default() -> Self {
31 Self {
32 topics: Vec::new(),
33 response_partition_limit: 2_000i32,
34 cursor: None,
35 unknown_tagged_fields: Default::default(),
36 }
37 }
38}
39
40impl Encode for DescribeTopicPartitionsRequest {
41 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
42 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
43 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
44 }
45 let flex = is_flexible(version);
46 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
47 if version >= 0 { put_i32(buf, self.response_partition_limit) }
48 if version >= 0 { match &self.cursor { None => { buf.put_i8(-1); }, Some(v) => { buf.put_i8(1); v.encode(buf, version)?; } } }
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 { 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 }; }
59 if version >= 0 { n += 4; }
60 if version >= 0 { n += 1 + self.cursor.as_ref().map_or(0, |v| v.encoded_len(version)); }
61 if flex {
62 let known_pairs: Vec<(u32, usize)> = Vec::new();
63 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
64 }
65 n
66 }
67}
68
69impl<'de> Decode<'de> for DescribeTopicPartitionsRequest {
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 { api_key: API_KEY, version });
73 }
74 let flex = is_flexible(version);
75 let mut out = Self::default();
76 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(buf, version)?); } v }; }
77 if version >= 0 { out.response_partition_limit = get_i32(buf)?; }
78 if version >= 0 { out.cursor = if get_i8(buf)? < 0 { None } else { Some(Cursor::decode(buf, version)?) }; }
79 if flex {
80 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
81 Ok(false)
82 })?;
83 }
84 Ok(out)
85 }
86}
87
88#[derive(Debug, Clone, PartialEq, Eq, Default)]
89pub struct TopicRequest {
90 pub name: String,
91 pub unknown_tagged_fields: UnknownTaggedFields,
92}
93
94impl Encode for TopicRequest {
95 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
96 let flex = version >= 0;
97 if version >= 0 { if flex { put_compact_string(buf, &self.name) } else { put_string(buf, &self.name) } }
98 if flex {
99 let tagged = WriteTaggedFields::new();
100 tagged.write(buf, &self.unknown_tagged_fields);
101 }
102 Ok(())
103 }
104 fn encoded_len(&self, version: i16) -> usize {
105 let flex = version >= 0;
106 let mut n: usize = 0;
107 if version >= 0 { n += if flex { compact_string_len(&self.name) } else { string_len(&self.name) }; }
108 if flex {
109 let known_pairs: Vec<(u32, usize)> = Vec::new();
110 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
111 }
112 n
113 }
114}
115
116impl<'de> Decode<'de> for TopicRequest {
117 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
118 let flex = version >= 0;
119 let mut out = Self::default();
120 if version >= 0 { out.name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
121 if flex {
122 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
123 Ok(false)
124 })?;
125 }
126 Ok(out)
127 }
128}
129
130#[derive(Debug, Clone, PartialEq, Eq, Default)]
131pub struct Cursor {
132 pub topic_name: String,
133 pub partition_index: i32,
134 pub unknown_tagged_fields: UnknownTaggedFields,
135}
136
137impl Encode for Cursor {
138 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
139 let flex = version >= 0;
140 if version >= 0 { if flex { put_compact_string(buf, &self.topic_name) } else { put_string(buf, &self.topic_name) } }
141 if version >= 0 { put_i32(buf, self.partition_index) }
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 >= 0;
150 let mut n: usize = 0;
151 if version >= 0 { n += if flex { compact_string_len(&self.topic_name) } else { string_len(&self.topic_name) }; }
152 if version >= 0 { n += 4; }
153 if flex {
154 let known_pairs: Vec<(u32, usize)> = Vec::new();
155 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
156 }
157 n
158 }
159}
160
161impl<'de> Decode<'de> for Cursor {
162 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
163 let flex = version >= 0;
164 let mut out = Self::default();
165 if version >= 0 { out.topic_name = if flex { get_compact_string_owned(buf)? } else { get_string_owned(buf)? }; }
166 if version >= 0 { out.partition_index = get_i32(buf)?; }
167 if flex {
168 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
169 Ok(false)
170 })?;
171 }
172 Ok(out)
173 }
174}
175
176#[must_use]
179#[allow(unused_comparisons)]
180pub fn default_json(version: i16) -> ::serde_json::Value {
181 let mut obj = ::serde_json::Map::new();
182 obj.insert("topics".to_string(), ::serde_json::Value::Array(vec![]));
183 obj.insert("responsePartitionLimit".to_string(), ::serde_json::json!(2000));
184 obj.insert("cursor".to_string(), ::serde_json::Value::Null);
185 ::serde_json::Value::Object(obj)
186}
187
188impl crate::ProtocolRequest for DescribeTopicPartitionsRequest {
189 const API_KEY: i16 = API_KEY;
190 const MIN_VERSION: i16 = MIN_VERSION;
191 const MAX_VERSION: i16 = MAX_VERSION;
192 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
193 type Response = super::describe_topic_partitions_response::DescribeTopicPartitionsResponse;
194}