Skip to main content

msg_bebop/
msg.rs

1//
2// This code was generated by a tool.
3//
4//
5//   bebopc version:
6//       3.2.0
7//
8//
9//   bebopc source:
10//       https://github.com/6over3/bebop
11//
12//
13// Changes to this file may cause incorrect behavior and will be lost if
14// the code is regenerated.
15//
16
17#![allow(warnings)]
18
19use ::std::io::Write as _;
20use ::core::convert::TryInto as _;
21use ::bebop::FixedSized as _;
22
23#[derive(Clone, Debug, PartialEq)]
24pub struct Msg<'raw> {
25    pub body: &'raw str,
26    pub from_id: &'raw str,
27    pub id: &'raw str,
28    pub to_ids: ::std::vec::Vec<&'raw str>,
29    pub _type: &'raw str,
30}
31
32impl<'raw> ::bebop::SubRecord<'raw> for Msg<'raw> {
33    const MIN_SERIALIZED_SIZE: usize =
34        <&'raw str>::MIN_SERIALIZED_SIZE +
35        <&'raw str>::MIN_SERIALIZED_SIZE +
36        <&'raw str>::MIN_SERIALIZED_SIZE +
37        <::std::vec::Vec<&'raw str>>::MIN_SERIALIZED_SIZE +
38        <&'raw str>::MIN_SERIALIZED_SIZE;
39
40    #[inline]
41    fn serialized_size(&self) -> usize {
42        self.body.serialized_size() +
43        self.from_id.serialized_size() +
44        self.id.serialized_size() +
45        self.to_ids.serialized_size() +
46        self._type.serialized_size()
47    }
48
49    ::bebop::define_serialize_chained!(Self => |zelf, dest| {
50        Ok(
51            zelf.body._serialize_chained(dest)? +
52            zelf.from_id._serialize_chained(dest)? +
53            zelf.id._serialize_chained(dest)? +
54            zelf.to_ids._serialize_chained(dest)? +
55            zelf._type._serialize_chained(dest)?
56        )
57    });
58
59    fn _deserialize_chained(raw: &'raw [u8]) -> ::bebop::DeResult<(usize, Self)> {
60        let mut i = 0;
61        if raw.len() - i < Self::MIN_SERIALIZED_SIZE {
62            let missing = Self::MIN_SERIALIZED_SIZE - (raw.len() - i);
63            return Err(::bebop::DeserializeError::MoreDataExpected(missing));
64        }
65
66        let (read, v0) = ::bebop::SubRecord::_deserialize_chained(&raw[i..])?;
67        i += read;
68        let (read, v1) = ::bebop::SubRecord::_deserialize_chained(&raw[i..])?;
69        i += read;
70        let (read, v2) = ::bebop::SubRecord::_deserialize_chained(&raw[i..])?;
71        i += read;
72        let (read, v3) = ::bebop::SubRecord::_deserialize_chained(&raw[i..])?;
73        i += read;
74        let (read, v4) = ::bebop::SubRecord::_deserialize_chained(&raw[i..])?;
75        i += read;
76
77        Ok((i, Self {
78            body: v0,
79            from_id: v1,
80            id: v2,
81            to_ids: v3,
82            _type: v4,
83        }))
84    }
85}
86
87impl<'raw> ::bebop::Record<'raw> for Msg<'raw> {}
88
89#[cfg(feature = "bebop-owned-all")]
90pub mod owned {
91    #![allow(warnings)]
92
93    use ::std::io::Write as _;
94    use ::core::convert::TryInto as _;
95    use ::bebop::FixedSized as _;
96
97    #[derive(Clone, Debug, PartialEq)]
98    pub struct Msg {
99        pub body: String,
100        pub from_id: String,
101        pub id: String,
102        pub to_ids: ::std::vec::Vec<String>,
103        pub _type: String,
104    }
105
106    impl<'raw> ::core::convert::From<super::Msg<'raw>> for Msg {
107        fn from(value: super::Msg) -> Self {
108            Self {
109                body: value.body.into(),
110                from_id: value.from_id.into(),
111                id: value.id.into(),
112                to_ids: value.to_ids.into_iter().map(|value| value.into()).collect(),
113                _type: value._type.into(),
114            }
115        }
116    }
117
118    impl<'raw> ::bebop::SubRecord<'raw> for Msg {
119        const MIN_SERIALIZED_SIZE: usize =
120            <String>::MIN_SERIALIZED_SIZE +
121            <String>::MIN_SERIALIZED_SIZE +
122            <String>::MIN_SERIALIZED_SIZE +
123            <::std::vec::Vec<String>>::MIN_SERIALIZED_SIZE +
124            <String>::MIN_SERIALIZED_SIZE;
125
126        #[inline]
127        fn serialized_size(&self) -> usize {
128            self.body.serialized_size() +
129            self.from_id.serialized_size() +
130            self.id.serialized_size() +
131            self.to_ids.serialized_size() +
132            self._type.serialized_size()
133        }
134
135        ::bebop::define_serialize_chained!(Self => |zelf, dest| {
136            Ok(
137                zelf.body._serialize_chained(dest)? +
138                zelf.from_id._serialize_chained(dest)? +
139                zelf.id._serialize_chained(dest)? +
140                zelf.to_ids._serialize_chained(dest)? +
141                zelf._type._serialize_chained(dest)?
142            )
143        });
144
145        fn _deserialize_chained(raw: &'raw [u8]) -> ::bebop::DeResult<(usize, Self)> {
146            let mut i = 0;
147            if raw.len() - i < Self::MIN_SERIALIZED_SIZE {
148                let missing = Self::MIN_SERIALIZED_SIZE - (raw.len() - i);
149                return Err(::bebop::DeserializeError::MoreDataExpected(missing));
150            }
151
152            let (read, v0) = ::bebop::SubRecord::_deserialize_chained(&raw[i..])?;
153            i += read;
154            let (read, v1) = ::bebop::SubRecord::_deserialize_chained(&raw[i..])?;
155            i += read;
156            let (read, v2) = ::bebop::SubRecord::_deserialize_chained(&raw[i..])?;
157            i += read;
158            let (read, v3) = ::bebop::SubRecord::_deserialize_chained(&raw[i..])?;
159            i += read;
160            let (read, v4) = ::bebop::SubRecord::_deserialize_chained(&raw[i..])?;
161            i += read;
162
163            Ok((i, Self {
164                body: v0,
165                from_id: v1,
166                id: v2,
167                to_ids: v3,
168                _type: v4,
169            }))
170        }
171    }
172
173    impl<'raw> ::bebop::Record<'raw> for Msg {}}