Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
RemoteLogSegmentMetadataUpdateRecord.owned.rs

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