Skip to main content

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

1// AUTO-GENERATED by crabka-protocol-codegen against a9ce3221537b8653448750697915607dc7936cf3. Do not edit.
2
3use crate::primitives::string_bytes::{
4    compact_string_len, get_compact_string_owned, get_string_owned, put_compact_string, put_string,
5    string_len,
6};
7use crate::tagged_fields::{WriteTaggedFields, read_tagged_fields, tagged_fields_len};
8use crate::{Decode, Encode, ProtocolError, UnknownTaggedFields};
9use bytes::{Buf, BufMut};
10pub const MIN_VERSION: i16 = 0;
11pub const MAX_VERSION: i16 = 0;
12pub const FLEXIBLE_MIN: i16 = 0;
13#[inline]
14fn is_flexible(version: i16) -> bool {
15    version >= FLEXIBLE_MIN
16}
17#[derive(Debug, Clone, PartialEq, Eq, Default)]
18pub struct TopicRecord {
19    pub name: String,
20    pub topic_id: crate::primitives::uuid::Uuid,
21    pub unknown_tagged_fields: UnknownTaggedFields,
22}
23impl Encode for TopicRecord {
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                "TopicRecord version out of range",
28            ));
29        }
30        let flex = is_flexible(version);
31        if version >= 0 {
32            if flex {
33                put_compact_string(buf, &self.name);
34            } else {
35                put_string(buf, &self.name);
36            }
37        }
38        if version >= 0 {
39            crate::primitives::uuid::put_uuid(buf, self.topic_id);
40        }
41        if flex {
42            let tagged = WriteTaggedFields::new();
43            tagged.write(buf, &self.unknown_tagged_fields);
44        }
45        Ok(())
46    }
47    fn encoded_len(&self, version: i16) -> usize {
48        let flex = is_flexible(version);
49        let mut n: usize = 0;
50        if version >= 0 {
51            n += if flex {
52                compact_string_len(&self.name)
53            } else {
54                string_len(&self.name)
55            };
56        }
57        if version >= 0 {
58            n += 16;
59        }
60        if flex {
61            let known_pairs: Vec<(u32, usize)> = Vec::new();
62            n += tagged_fields_len(&known_pairs, &self.unknown_tagged_fields);
63        }
64        n
65    }
66}
67impl Decode<'_> for TopicRecord {
68    fn decode<B: Buf>(buf: &mut B, version: i16) -> Result<Self, ProtocolError> {
69        if !(MIN_VERSION..=MAX_VERSION).contains(&version) {
70            return Err(ProtocolError::SchemaMismatch(
71                "TopicRecord version out of range",
72            ));
73        }
74        let flex = is_flexible(version);
75        let mut out = Self::default();
76        if version >= 0 {
77            out.name = if flex {
78                get_compact_string_owned(buf)?
79            } else {
80                get_string_owned(buf)?
81            };
82        }
83        if version >= 0 {
84            out.topic_id = crate::primitives::uuid::get_uuid(buf)?;
85        }
86        if flex {
87            out.unknown_tagged_fields = read_tagged_fields(buf, |_tag, _payload| Ok(false))?;
88        }
89        Ok(out)
90    }
91}
92#[cfg(test)]
93impl TopicRecord {
94    #[must_use]
95    pub fn populated(version: i16) -> Self {
96        let mut m = Self::default();
97        if version >= 0 {
98            m.name = "x".to_string();
99        }
100        if version >= 0 {
101            m.topic_id = crate::primitives::uuid::Uuid([1u8; 16]);
102        }
103        m
104    }
105}
106/// Default JSON payload matching `Self::default()` for JVM oracle differential testing.
107/// Only includes fields valid for the given version.
108#[must_use]
109#[allow(unused_comparisons)]
110pub fn default_json(version: i16) -> ::serde_json::Value {
111    let mut obj = ::serde_json::Map::new();
112    obj.insert(
113        "name".to_string(),
114        ::serde_json::Value::String(String::new()),
115    );
116    obj.insert(
117        "topicId".to_string(),
118        ::serde_json::Value::String("AAAAAAAAAAAAAAAAAAAAAA".to_string()),
119    );
120    ::serde_json::Value::Object(obj)
121}