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