catbuffer_rust/
namespace_expiry_receipt_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::namespace_id_dto::*;
24use super::receipt_builder::*;
25use super::receipt_type_dto::*;
26
27/// Binary layout for a namespace expiry receipt.
28#[derive(Debug, Clone)]
29pub struct NamespaceExpiryReceiptBuilder {
30    /// Receipt.
31    super_object: ReceiptBuilder,
32    /// Expiring namespace id.
33    artifact_id: NamespaceIdDto,
34}
35
36
37impl NamespaceExpiryReceiptBuilder {
38    /// Creates an instance of NamespaceExpiryReceiptBuilder from binary payload.
39    /// payload: Byte payload to use to serialize the object.
40    /// # Returns
41    /// A NamespaceExpiryReceiptBuilder.
42    pub fn from_binary(_bytes: &[u8]) -> Self {
43        let super_object = ReceiptBuilder::from_binary(_bytes);
44        let mut _bytes = _bytes[super_object.get_size()..].to_vec();
45        let artifact_id = NamespaceIdDto::from_binary(&_bytes); // kind:CUSTOM1
46        let mut _bytes = _bytes[artifact_id.get_size()..].to_vec();
47        NamespaceExpiryReceiptBuilder { super_object, artifact_id }
48    }
49
50    /// Gets expiring namespace id.
51    ///
52    /// # Returns
53    /// A Expiring namespace id.
54    pub fn get_artifact_id(&self) -> NamespaceIdDto {
55        self.artifact_id.clone()
56    }
57
58    /// Gets the size of the type.
59    ///
60    /// Returns:
61    /// A size in bytes.
62    pub fn get_size(&self) -> usize {
63        let mut size = self.super_object.get_size();
64        size += self.artifact_id.get_size(); // artifact_id;
65        size
66    }
67
68    /// Serializes self to bytes.
69    ///
70    /// # Returns
71    /// A Serialized bytes.
72    pub fn serializer(&self) -> Vec<u8> {
73        let mut buf: Vec<u8> = vec![];
74        buf.append(&mut self.super_object.serializer());
75        buf.append(&mut self.artifact_id.serializer()); // kind:CUSTOM
76        buf
77    }
78}
79