crabka_protocol/opt/rustwide/workdir/generated/
AssignReplicasToDirsRequest.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i32, get_i64, put_i32, put_i64};
6use crate::tagged_fields::{read_tagged_fields, tagged_fields_len, WriteTaggedFields};
7use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
8
9pub const API_KEY: i16 = 73;
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 0;
12pub const FLEXIBLE_MIN: i16 = 0;
13
14#[inline]
15fn is_flexible(version: i16) -> bool { version >= FLEXIBLE_MIN }
16
17#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct AssignReplicasToDirsRequest {
19 pub broker_id: i32,
20 pub broker_epoch: i64,
21 pub directories: Vec<DirectoryData>,
22 pub unknown_tagged_fields: UnknownTaggedFields,
23}
24
25impl Default for AssignReplicasToDirsRequest {
26 fn default() -> Self {
27 Self {
28 broker_id: 0i32,
29 broker_epoch: -1i64,
30 directories: Vec::new(),
31 unknown_tagged_fields: Default::default(),
32 }
33 }
34}
35
36impl Encode for AssignReplicasToDirsRequest {
37 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
38 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
39 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
40 }
41 let flex = is_flexible(version);
42 if version >= 0 { put_i32(buf, self.broker_id) }
43 if version >= 0 { put_i64(buf, self.broker_epoch) }
44 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.directories).len(), flex); for it in &self.directories { it.encode(buf, version)?; } } }
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 { n += 4; }
55 if version >= 0 { n += 8; }
56 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.directories).len(), flex); let body: usize = (self.directories).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
57 if flex {
58 let known_pairs: Vec<(u32, usize)> = Vec::new();
59 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
60 }
61 n
62 }
63}
64
65impl<'de> Decode<'de> for AssignReplicasToDirsRequest {
66 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
67 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
68 return Err(ProtocolError::UnsupportedVersion { api_key: API_KEY, version });
69 }
70 let flex = is_flexible(version);
71 let mut out = Self::default();
72 if version >= 0 { out.broker_id = get_i32(buf)?; }
73 if version >= 0 { out.broker_epoch = get_i64(buf)?; }
74 if version >= 0 { out.directories = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(DirectoryData::decode(buf, version)?); } v }; }
75 if flex {
76 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
77 Ok(false)
78 })?;
79 }
80 Ok(out)
81 }
82}
83
84#[derive(Debug, Clone, PartialEq, Eq, Default)]
85pub struct DirectoryData {
86 pub id: crate::primitives::uuid::Uuid,
87 pub topics: Vec<TopicData>,
88 pub unknown_tagged_fields: UnknownTaggedFields,
89}
90
91impl Encode for DirectoryData {
92 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
93 let flex = version >= 0;
94 if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.id) }
95 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.topics).len(), flex); for it in &self.topics { it.encode(buf, version)?; } } }
96 if flex {
97 let tagged = WriteTaggedFields::new();
98 tagged.write(buf, &self.unknown_tagged_fields);
99 }
100 Ok(())
101 }
102 fn encoded_len(&self, version: i16) -> usize {
103 let flex = version >= 0;
104 let mut n: usize = 0;
105 if version >= 0 { n += 16; }
106 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 }; }
107 if flex {
108 let known_pairs: Vec<(u32, usize)> = Vec::new();
109 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
110 }
111 n
112 }
113}
114
115impl<'de> Decode<'de> for DirectoryData {
116 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
117 let flex = version >= 0;
118 let mut out = Self::default();
119 if version >= 0 { out.id = crate::primitives::uuid::get_uuid(buf)?; }
120 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(TopicData::decode(buf, version)?); } v }; }
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 TopicData {
132 pub topic_id: crate::primitives::uuid::Uuid,
133 pub partitions: Vec<PartitionData>,
134 pub unknown_tagged_fields: UnknownTaggedFields,
135}
136
137impl Encode for TopicData {
138 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
139 let flex = version >= 0;
140 if version >= 0 { crate::primitives::uuid::put_uuid(buf, self.topic_id) }
141 if version >= 0 { { crate::primitives::array::put_array_len(buf, (self.partitions).len(), flex); for it in &self.partitions { it.encode(buf, version)?; } } }
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 += 16; }
152 if version >= 0 { n += { let prefix = crate::primitives::array::array_len_prefix_len((self.partitions).len(), flex); let body: usize = (self.partitions).iter().map(|it| it.encoded_len(version)).sum(); prefix + body }; }
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 TopicData {
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_id = crate::primitives::uuid::get_uuid(buf)?; }
166 if version >= 0 { out.partitions = { let n = crate::primitives::array::get_array_len(buf, flex)?; let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(PartitionData::decode(buf, version)?); } v }; }
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#[derive(Debug, Clone, PartialEq, Eq, Default)]
177pub struct PartitionData {
178 pub partition_index: i32,
179 pub unknown_tagged_fields: UnknownTaggedFields,
180}
181
182impl Encode for PartitionData {
183 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
184 let flex = version >= 0;
185 if version >= 0 { put_i32(buf, self.partition_index) }
186 if flex {
187 let tagged = WriteTaggedFields::new();
188 tagged.write(buf, &self.unknown_tagged_fields);
189 }
190 Ok(())
191 }
192 fn encoded_len(&self, version: i16) -> usize {
193 let flex = version >= 0;
194 let mut n: usize = 0;
195 if version >= 0 { n += 4; }
196 if flex {
197 let known_pairs: Vec<(u32, usize)> = Vec::new();
198 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
199 }
200 n
201 }
202}
203
204impl<'de> Decode<'de> for PartitionData {
205 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
206 let flex = version >= 0;
207 let mut out = Self::default();
208 if version >= 0 { out.partition_index = get_i32(buf)?; }
209 if flex {
210 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| {
211 Ok(false)
212 })?;
213 }
214 Ok(out)
215 }
216}
217
218#[must_use]
221#[allow(unused_comparisons)]
222pub fn default_json(version: i16) -> ::serde_json::Value {
223 let mut obj = ::serde_json::Map::new();
224 obj.insert("brokerId".to_string(), ::serde_json::json!(0));
225 obj.insert("brokerEpoch".to_string(), ::serde_json::json!(-1));
226 obj.insert("directories".to_string(), ::serde_json::Value::Array(vec![]));
227 ::serde_json::Value::Object(obj)
228}
229
230impl crate::ProtocolRequest for AssignReplicasToDirsRequest {
231 const API_KEY: i16 = API_KEY;
232 const MIN_VERSION: i16 = MIN_VERSION;
233 const MAX_VERSION: i16 = MAX_VERSION;
234 const FLEXIBLE_MIN: i16 = FLEXIBLE_MIN;
235 type Response = super::assign_replicas_to_dirs_response::AssignReplicasToDirsResponse;
236}