crabka_protocol/opt/rustwide/workdir/generated/
RemoteLogSegmentMetadataUpdateRecord.owned.rs1use crate::primitives::fixed::{get_i8, get_i32, get_i64, put_i8, put_i32, put_i64};
4use crate::primitives::string_bytes::{
5 compact_nullable_bytes_len, get_compact_nullable_bytes_owned, get_nullable_bytes_owned,
6 nullable_bytes_len, put_compact_nullable_bytes, put_nullable_bytes,
7};
8use crate::primitives::string_bytes::{
9 compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
10 string_len,
11};
12use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
13use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
14use bytes::{Buf, BufMut};
15pub const MIN_VERSION: i16 = 0;
16pub const MAX_VERSION: i16 = 0;
17pub const FLEXIBLE_MIN: i16 = 0;
18#[inline]
19fn is_flexible(version: i16) -> bool {
20 version >= FLEXIBLE_MIN
21}
22#[derive(Debug, Clone, PartialEq, Eq, Default)]
23pub struct RemoteLogSegmentMetadataUpdateRecord {
24 pub remote_log_segment_id: RemoteLogSegmentIdEntry,
25 pub broker_id: i32,
26 pub event_timestamp_ms: i64,
27 pub custom_metadata: Option<::bytes::Bytes>,
28 pub remote_log_segment_state: i8,
29 pub unknown_tagged_fields: UnknownTaggedFields,
30}
31impl Encode for RemoteLogSegmentMetadataUpdateRecord {
32 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
33 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
34 return Err(ProtocolError::SchemaMismatch(
35 "RemoteLogSegmentMetadataUpdateRecord version out of range",
36 ));
37 }
38 let flex = is_flexible(version);
39 if version >= 0 {
40 self.remote_log_segment_id.encode(buf, version)?;
41 }
42 if version >= 0 {
43 put_i32(buf, self.broker_id);
44 }
45 if version >= 0 {
46 put_i64(buf, self.event_timestamp_ms);
47 }
48 if version >= 0 {
49 if flex {
50 put_compact_nullable_bytes(buf, self.custom_metadata.as_deref());
51 } else {
52 put_nullable_bytes(buf, self.custom_metadata.as_deref());
53 }
54 }
55 if version >= 0 {
56 put_i8(buf, self.remote_log_segment_state);
57 }
58 if flex {
59 let tagged = WriteTaggedFields::new();
60 tagged.write(buf, &self.unknown_tagged_fields);
61 }
62 Ok(())
63 }
64 fn encoded_len(&self, version: i16) -> usize {
65 let flex = is_flexible(version);
66 let mut n: usize = 0;
67 if version >= 0 {
68 n += self.remote_log_segment_id.encoded_len(version);
69 }
70 if version >= 0 {
71 n += 4;
72 }
73 if version >= 0 {
74 n += 8;
75 }
76 if version >= 0 {
77 n += if flex {
78 compact_nullable_bytes_len(self.custom_metadata.as_deref())
79 } else {
80 nullable_bytes_len(self.custom_metadata.as_deref())
81 };
82 }
83 if version >= 0 {
84 n += 1;
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 Decode<'_> for RemoteLogSegmentMetadataUpdateRecord {
94 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
95 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
96 return Err(ProtocolError::SchemaMismatch(
97 "RemoteLogSegmentMetadataUpdateRecord version out of range",
98 ));
99 }
100 let flex = is_flexible(version);
101 let mut out = Self::default();
102 if version >= 0 {
103 out.remote_log_segment_id = RemoteLogSegmentIdEntry::decode(buf, version)?;
104 }
105 if version >= 0 {
106 out.broker_id = get_i32(buf)?;
107 }
108 if version >= 0 {
109 out.event_timestamp_ms = get_i64(buf)?;
110 }
111 if version >= 0 {
112 out.custom_metadata = if flex {
113 get_compact_nullable_bytes_owned(buf)?
114 } else {
115 get_nullable_bytes_owned(buf)?
116 };
117 }
118 if version >= 0 {
119 out.remote_log_segment_state = get_i8(buf)?;
120 }
121 if flex {
122 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
123 }
124 Ok(out)
125 }
126}
127#[cfg(test)]
128impl RemoteLogSegmentMetadataUpdateRecord {
129 #[must_use]
130 pub fn populated(version: i16) -> Self {
131 let mut m = Self::default();
132 if version >= 0 {
133 m.remote_log_segment_id = RemoteLogSegmentIdEntry::populated(version);
134 }
135 if version >= 0 {
136 m.broker_id = 1i32;
137 }
138 if version >= 0 {
139 m.event_timestamp_ms = 1i64;
140 }
141 if version >= 0 {
142 m.custom_metadata = Some(::bytes::Bytes::from_static(b"x"));
143 }
144 if version >= 0 {
145 m.remote_log_segment_state = 1i8;
146 }
147 m
148 }
149}
150#[derive(Debug, Clone, PartialEq, Eq, Default)]
151pub struct RemoteLogSegmentIdEntry {
152 pub topic_id_partition: TopicIdPartitionEntry,
153 pub id: crate::primitives::uuid::Uuid,
154 pub unknown_tagged_fields: UnknownTaggedFields,
155}
156impl Encode for RemoteLogSegmentIdEntry {
157 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
158 let flex = version >= 0;
159 if version >= 0 {
160 self.topic_id_partition.encode(buf, version)?;
161 }
162 if version >= 0 {
163 crate::primitives::uuid::put_uuid(buf, self.id);
164 }
165 if flex {
166 let tagged = WriteTaggedFields::new();
167 tagged.write(buf, &self.unknown_tagged_fields);
168 }
169 Ok(())
170 }
171 fn encoded_len(&self, version: i16) -> usize {
172 let flex = version >= 0;
173 let mut n: usize = 0;
174 if version >= 0 {
175 n += self.topic_id_partition.encoded_len(version);
176 }
177 if version >= 0 {
178 n += 16;
179 }
180 if flex {
181 let known_pairs: Vec<(u32, usize)> = Vec::new();
182 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
183 }
184 n
185 }
186}
187impl Decode<'_> for RemoteLogSegmentIdEntry {
188 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
189 let flex = version >= 0;
190 let mut out = Self::default();
191 if version >= 0 {
192 out.topic_id_partition = TopicIdPartitionEntry::decode(buf, version)?;
193 }
194 if version >= 0 {
195 out.id = crate::primitives::uuid::get_uuid(buf)?;
196 }
197 if flex {
198 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
199 }
200 Ok(out)
201 }
202}
203#[cfg(test)]
204impl RemoteLogSegmentIdEntry {
205 #[must_use]
206 pub fn populated(version: i16) -> Self {
207 let mut m = Self::default();
208 if version >= 0 {
209 m.topic_id_partition = TopicIdPartitionEntry::populated(version);
210 }
211 if version >= 0 {
212 m.id = crate::primitives::uuid::Uuid([1u8; 16]);
213 }
214 m
215 }
216}
217#[derive(Debug, Clone, PartialEq, Eq, Default)]
218pub struct TopicIdPartitionEntry {
219 pub name: String,
220 pub id: crate::primitives::uuid::Uuid,
221 pub partition: i32,
222 pub unknown_tagged_fields: UnknownTaggedFields,
223}
224impl Encode for TopicIdPartitionEntry {
225 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
226 let flex = version >= 0;
227 if version >= 0 {
228 if flex {
229 put_compact_string(buf, &self.name);
230 } else {
231 put_string(buf, &self.name);
232 }
233 }
234 if version >= 0 {
235 crate::primitives::uuid::put_uuid(buf, self.id);
236 }
237 if version >= 0 {
238 put_i32(buf, self.partition);
239 }
240 if flex {
241 let tagged = WriteTaggedFields::new();
242 tagged.write(buf, &self.unknown_tagged_fields);
243 }
244 Ok(())
245 }
246 fn encoded_len(&self, version: i16) -> usize {
247 let flex = version >= 0;
248 let mut n: usize = 0;
249 if version >= 0 {
250 n += if flex {
251 compact_string_len(&self.name)
252 } else {
253 string_len(&self.name)
254 };
255 }
256 if version >= 0 {
257 n += 16;
258 }
259 if version >= 0 {
260 n += 4;
261 }
262 if flex {
263 let known_pairs: Vec<(u32, usize)> = Vec::new();
264 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
265 }
266 n
267 }
268}
269impl Decode<'_> for TopicIdPartitionEntry {
270 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
271 let flex = version >= 0;
272 let mut out = Self::default();
273 if version >= 0 {
274 out.name = if flex {
275 get_compact_string_owned(buf)?
276 } else {
277 get_string_owned(buf)?
278 };
279 }
280 if version >= 0 {
281 out.id = crate::primitives::uuid::get_uuid(buf)?;
282 }
283 if version >= 0 {
284 out.partition = get_i32(buf)?;
285 }
286 if flex {
287 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
288 }
289 Ok(out)
290 }
291}
292#[cfg(test)]
293impl TopicIdPartitionEntry {
294 #[must_use]
295 pub fn populated(version: i16) -> Self {
296 let mut m = Self::default();
297 if version >= 0 {
298 m.name = "x".to_string();
299 }
300 if version >= 0 {
301 m.id = crate::primitives::uuid::Uuid([1u8; 16]);
302 }
303 if version >= 0 {
304 m.partition = 1i32;
305 }
306 m
307 }
308}
309#[must_use]
312#[allow(unused_comparisons)]
313pub fn default_json(version: i16) -> ::serde_json::Value {
314 let mut obj = ::serde_json::Map::new();
315 obj.insert("remoteLogSegmentId".to_string(), {
316 let mut m = ::serde_json::Map::new();
317 m.insert("topicIdPartition".to_string(), {
318 let mut m = ::serde_json::Map::new();
319 m.insert(
320 "name".to_string(),
321 ::serde_json::Value::String(String::new()),
322 );
323 m.insert(
324 "id".to_string(),
325 ::serde_json::Value::String("AAAAAAAAAAAAAAAAAAAAAA".to_string()),
326 );
327 m.insert("partition".to_string(), ::serde_json::json!(0));
328 ::serde_json::Value::Object(m)
329 });
330 m.insert(
331 "id".to_string(),
332 ::serde_json::Value::String("AAAAAAAAAAAAAAAAAAAAAA".to_string()),
333 );
334 ::serde_json::Value::Object(m)
335 });
336 obj.insert("brokerId".to_string(), ::serde_json::json!(0));
337 obj.insert("eventTimestampMs".to_string(), ::serde_json::json!(0));
338 obj.insert("customMetadata".to_string(), ::serde_json::Value::Null);
339 obj.insert("remoteLogSegmentState".to_string(), ::serde_json::json!(0));
340 ::serde_json::Value::Object(obj)
341}