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