Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
4use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
5use bytes::{Buf, BufMut};
6pub const MIN_VERSION: i16 = 0;
7pub const MAX_VERSION: i16 = 0;
8pub const FLEXIBLE_MIN: i16 = 0;
9
10#[inline]
11fn is_flexible(version: i16) -> bool {
12    version >= FLEXIBLE_MIN
13}
14
15#[derive(Debug, Clone, PartialEq, Eq, Default)]
16pub struct NoOpRecord {
17    pub unknown_tagged_fields: UnknownTaggedFields,
18}
19impl Encode for NoOpRecord {
20    fn encode<B: BufMut>(&self, buf: &mut B, version: i16) -> Result<(), ProtocolError> {
21        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
22            return Err(ProtocolError::SchemaMismatch(
23                "NoOpRecord version out of range",
24            ));
25        }
26        let flex = is_flexible(version);
27        if flex {
28            let tagged = WriteTaggedFields::new();
29            tagged.write(buf, &self.unknown_tagged_fields);
30        }
31        Ok(())
32    }
33    fn encoded_len(&self, version: i16) -> usize {
34        let flex = is_flexible(version);
35        let mut n: usize = 0;
36        if flex {
37            let known_pairs: Vec<(u32, usize)> = Vec::new();
38            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
39        }
40        n
41    }
42}
43impl Decode<'_> for NoOpRecord {
44    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
45        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
46            return Err(ProtocolError::SchemaMismatch(
47                "NoOpRecord version out of range",
48            ));
49        }
50        let flex = is_flexible(version);
51        let mut out = Self::default();
52        if flex {
53            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
54        }
55        Ok(out)
56    }
57}
58#[cfg(test)]
59impl NoOpRecord {
60    #[must_use]
61    pub fn populated(version: i16) -> Self {
62        Self::default()
63    }
64}
65
66/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
67/// Only includes fields valid for the given version.
68#[must_use]
69#[allow(unused_comparisons)]
70pub fn default_json(version: i16) -> ::serde_json::Value {
71    let mut obj = ::serde_json::Map::new();
72    ::serde_json::Value::Object(obj)
73}