catbuffer_rust/
mosaic_address_restriction_entry_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::address_dto::*;
23use super::address_key_value_set_builder::*;
24use super::generator_utils::*;
25use super::mosaic_id_dto::*;
26
27/// Binary layout for a mosaic restriction.
28#[derive(Debug, Clone)]
29pub struct MosaicAddressRestrictionEntryBuilder {
30    /// Identifier of the mosaic to which the restriction applies.
31    mosaic_id: MosaicIdDto,
32    /// Address being restricted.
33    address: AddressDto,
34    /// Address key value restriction set.
35    key_pairs: AddressKeyValueSetBuilder,
36}
37
38
39impl MosaicAddressRestrictionEntryBuilder {
40    /// Creates an instance of MosaicAddressRestrictionEntryBuilder from binary payload.
41    /// payload: Byte payload to use to serialize the object.
42    /// # Returns
43    /// A MosaicAddressRestrictionEntryBuilder.
44    pub fn from_binary(_bytes: &[u8]) -> Self {
45        let mosaic_id = MosaicIdDto::from_binary(&_bytes); // kind:CUSTOM1
46        let mut _bytes = _bytes[mosaic_id.get_size()..].to_vec();
47        let address = AddressDto::from_binary(&_bytes); // kind:CUSTOM1
48        let mut _bytes = _bytes[address.get_size()..].to_vec();
49        let key_pairs = AddressKeyValueSetBuilder::from_binary(&_bytes); // kind:CUSTOM1
50        let mut _bytes = _bytes[key_pairs.get_size()..].to_vec();
51        MosaicAddressRestrictionEntryBuilder { mosaic_id, address, key_pairs }
52    }
53
54    /// Gets identifier of the mosaic to which the restriction applies.
55    ///
56    /// # Returns
57    /// A Identifier of the mosaic to which the restriction applies.
58    pub fn get_mosaic_id(&self) -> MosaicIdDto {
59        self.mosaic_id.clone()
60    }
61
62    /// Gets address being restricted.
63    ///
64    /// # Returns
65    /// A Address being restricted.
66    pub fn get_address(&self) -> AddressDto {
67        self.address.clone()
68    }
69
70    /// Gets address key value restriction set.
71    ///
72    /// # Returns
73    /// A Address key value restriction set.
74    pub fn get_key_pairs(&self) -> AddressKeyValueSetBuilder {
75        self.key_pairs.clone()
76    }
77
78    /// Gets the size of the type.
79    ///
80    /// Returns:
81    /// A size in bytes.
82    pub fn get_size(&self) -> usize {
83        let mut size = 0;
84        size += self.mosaic_id.get_size(); // mosaic_id;
85        size += self.address.get_size(); // address;
86        size += self.key_pairs.get_size(); // key_pairs;
87        size
88    }
89
90    /// Serializes self to bytes.
91    ///
92    /// # Returns
93    /// A Serialized bytes.
94    pub fn serializer(&self) -> Vec<u8> {
95        let mut buf: Vec<u8> = vec![];
96        buf.append(&mut self.mosaic_id.serializer()); // kind:CUSTOM
97        buf.append(&mut self.address.serializer()); // kind:CUSTOM
98        buf.append(&mut self.key_pairs.serializer()); // kind:CUSTOM
99        buf
100    }
101}
102