Skip to main content

crabka_protocol/opt/rustwide/workdir/generated/
SnapshotFooterRecord.owned.rs

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use bytes::{Buf, BufMut};
4
5use crate::primitives::fixed::{get_i16, put_i16};
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 SnapshotFooterRecord {
19    pub version: i16,
20    pub unknown_tagged_fields: UnknownTaggedFields,
21}
22impl Encode for SnapshotFooterRecord {
23    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
24        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
25            return Err(ProtocolError::SchemaMismatch(
26                "SnapshotFooterRecord version out of range",
27            ));
28        }
29        let flex = is_flexible(version);
30        if version >= 0 {
31            put_i16(buf, self.version);
32        }
33        if flex {
34            let tagged = WriteTaggedFields::new();
35            tagged.write(buf, &self.unknown_tagged_fields);
36        }
37        Ok(())
38    }
39    fn encoded_len(&self, version: i16) -> usize {
40        let flex = is_flexible(version);
41        let mut n: usize = 0;
42        if version >= 0 {
43            n += 2;
44        }
45        if flex {
46            let known_pairs: Vec<(u32, usize)> = Vec::new();
47            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
48        }
49        n
50    }
51}
52impl Decode<'_> for SnapshotFooterRecord {
53    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
54        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
55            return Err(ProtocolError::SchemaMismatch(
56                "SnapshotFooterRecord version out of range",
57            ));
58        }
59        let flex = is_flexible(version);
60        let mut out = Self::default();
61        if version >= 0 {
62            out.version = get_i16(buf)?;
63        }
64        if flex {
65            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
66        }
67        Ok(out)
68    }
69}
70#[cfg(test)]
71impl SnapshotFooterRecord {
72    #[must_use]
73    pub fn populated(version: i16) -> Self {
74        let mut m = Self::default();
75        if version >= 0 {
76            m.version = 1i16;
77        }
78        m
79    }
80}
81
82/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
83/// Only includes fields valid for the given version.
84#[must_use]
85#[allow(unused_comparisons)]
86pub fn default_json(version: i16) -> ::serde_json::Value {
87    let mut obj = ::serde_json::Map::new();
88    obj.insert("version".to_string(), ::serde_json::json!(0));
89    ::serde_json::Value::Object(obj)
90}