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