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