Skip to main content

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