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