Skip to main content

krabka_protocol/opt/rustwide/workdir/generated/
SnapshotFooterRecord.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::fixed::{get_i16, put_i16},
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 SnapshotFooterRecord {
20    pub version: i16,
21    pub unknown_tagged_fields: UnknownTaggedFields,
22}
23impl Encode for SnapshotFooterRecord {
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                "SnapshotFooterRecord 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 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 flex {
47            let known_pairs: Vec<(u32, usize)> = Vec::new();
48            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
49        }
50        n
51    }
52}
53impl Decode<'_> for SnapshotFooterRecord {
54    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
55        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
56            return Err(ProtocolError::SchemaMismatch(
57                "SnapshotFooterRecord version out of range",
58            ));
59        }
60        let flex = is_flexible(version);
61        let mut out = Self::default();
62        if version >= 0 {
63            out.version = get_i16(buf)?;
64        }
65        if flex {
66            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
67        }
68        Ok(out)
69    }
70}
71#[cfg(test)]
72impl SnapshotFooterRecord {
73    #[must_use]
74    pub fn populated(version: i16) -> Self {
75        let mut m = Self::default();
76        if version >= 0 {
77            m.version = 1i16;
78        }
79        m
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}