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