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