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