Skip to main content

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