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