catbuffer_rust/namespace_lifetime_builder.rs
1/*
2 * // Copyright (c) 2016-2019, Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp.
3 * // Copyright (c) 2020-present, Jaguar0625, gimre, BloodyRookie.
4 * // All rights reserved.
5 * //
6 * // This file is part of Catapult.
7 * //
8 * // Catapult is free software: you can redistribute it and/or modify
9 * // it under the terms of the GNU Lesser General Public License as published by
10 * // the Free Software Foundation, either version 3 of the License, or
11 * // (at your option) any later version.
12 * //
13 * // Catapult is distributed in the hope that it will be useful,
14 * // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * // GNU Lesser General Public License for more details.
17 * //
18 * // You should have received a copy of the GNU Lesser General Public License
19 * // along with Catapult. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22use super::generator_utils::*;
23use super::height_dto::*;
24
25/// Binary layout for namespace lifetime.
26#[derive(Debug, Clone)]
27pub struct NamespaceLifetimeBuilder {
28 /// Start height.
29 lifetime_start: HeightDto,
30 /// End height.
31 lifetime_end: HeightDto,
32}
33
34
35impl NamespaceLifetimeBuilder {
36 /// Creates an instance of NamespaceLifetimeBuilder from binary payload.
37 /// payload: Byte payload to use to serialize the object.
38 /// # Returns
39 /// A NamespaceLifetimeBuilder.
40 pub fn from_binary(_bytes: &[u8]) -> Self {
41 let lifetime_start = HeightDto::from_binary(&_bytes); // kind:CUSTOM1
42 let mut _bytes = _bytes[lifetime_start.get_size()..].to_vec();
43 let lifetime_end = HeightDto::from_binary(&_bytes); // kind:CUSTOM1
44 let mut _bytes = _bytes[lifetime_end.get_size()..].to_vec();
45 NamespaceLifetimeBuilder { lifetime_start, lifetime_end }
46 }
47
48 /// Gets start height.
49 ///
50 /// # Returns
51 /// A Start height.
52 pub fn get_lifetime_start(&self) -> HeightDto {
53 self.lifetime_start.clone()
54 }
55
56 /// Gets end height.
57 ///
58 /// # Returns
59 /// A End height.
60 pub fn get_lifetime_end(&self) -> HeightDto {
61 self.lifetime_end.clone()
62 }
63
64 /// Gets the size of the type.
65 ///
66 /// Returns:
67 /// A size in bytes.
68 pub fn get_size(&self) -> usize {
69 let mut size = 0;
70 size += self.lifetime_start.get_size(); // lifetime_start;
71 size += self.lifetime_end.get_size(); // lifetime_end;
72 size
73 }
74
75 /// Serializes self to bytes.
76 ///
77 /// # Returns
78 /// A Serialized bytes.
79 pub fn serializer(&self) -> Vec<u8> {
80 let mut buf: Vec<u8> = vec![];
81 buf.append(&mut self.lifetime_start.serializer()); // kind:CUSTOM
82 buf.append(&mut self.lifetime_end.serializer()); // kind:CUSTOM
83 buf
84 }
85}
86