crabka_protocol/opt/rustwide/workdir/generated/
SnapshotHeaderRecord.owned.rs1use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, get_i64, put_i16, put_i64};
6use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
7use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
8pub const MIN_VERSION: i16 = 0;
9pub const MAX_VERSION: i16 = 0;
10pub const FLEXIBLE_MIN: i16 = 0;
11
12#[inline]
13fn is_flexible(version: i16) -> bool {
14 version >= FLEXIBLE_MIN
15}
16
17#[derive(Debug, Clone, PartialEq, Eq, Default)]
18pub struct SnapshotHeaderRecord {
19 pub version: i16,
20 pub last_contained_log_timestamp: i64,
21 pub unknown_tagged_fields: UnknownTaggedFields,
22}
23impl Encode for SnapshotHeaderRecord {
24 fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
25 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
26 return Err(ProtocolError::SchemaMismatch(
27 "SnapshotHeaderRecord version out of range",
28 ));
29 }
30 let flex = is_flexible(version);
31 if version >= 0 {
32 put_i16(buf, self.version);
33 }
34 if version >= 0 {
35 put_i64(buf, self.last_contained_log_timestamp);
36 }
37 if flex {
38 let tagged = WriteTaggedFields::new();
39 tagged.write(buf, &self.unknown_tagged_fields);
40 }
41 Ok(())
42 }
43 fn encoded_len(&self, version: i16) -> usize {
44 let flex = is_flexible(version);
45 let mut n: usize = 0;
46 if version >= 0 {
47 n += 2;
48 }
49 if version >= 0 {
50 n += 8;
51 }
52 if flex {
53 let known_pairs: Vec<(u32, usize)> = Vec::new();
54 n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
55 }
56 n
57 }
58}
59impl Decode<'_> for SnapshotHeaderRecord {
60 fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
61 if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
62 return Err(ProtocolError::SchemaMismatch(
63 "SnapshotHeaderRecord version out of range",
64 ));
65 }
66 let flex = is_flexible(version);
67 let mut out = Self::default();
68 if version >= 0 {
69 out.version = get_i16(buf)?;
70 }
71 if version >= 0 {
72 out.last_contained_log_timestamp = get_i64(buf)?;
73 }
74 if flex {
75 out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
76 }
77 Ok(out)
78 }
79}
80#[cfg(test)]
81impl SnapshotHeaderRecord {
82 #[must_use]
83 pub fn populated(version: i16) -> Self {
84 let mut m = Self::default();
85 if version >= 0 {
86 m.version = 1i16;
87 }
88 if version >= 0 {
89 m.last_contained_log_timestamp = 1i64;
90 }
91 m
92 }
93}
94
95#[must_use]
98#[allow(unused_comparisons)]
99pub fn default_json(version: i16) -> ::serde_json::Value {
100 let mut obj = ::serde_json::Map::new();
101 obj.insert("version".to_string(), ::serde_json::json!(0));
102 obj.insert(
103 "lastContainedLogTimestamp".to_string(),
104 ::serde_json::json!(0),
105 );
106 ::serde_json::Value::Object(obj)
107}