catbuffer_rust/address_alias_transaction_body_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::alias_action_dto::*;
24use super::generator_utils::*;
25use super::namespace_id_dto::*;
26
27/// Binary layout for an address alias transaction.
28#[derive(Debug, Clone)]
29pub struct AddressAliasTransactionBodyBuilder {
30 /// Identifier of the namespace that will become an alias.
31 pub namespace_id: NamespaceIdDto,
32 /// Aliased address.
33 pub address: AddressDto,
34 /// Alias action.
35 pub alias_action: AliasActionDto,
36}
37
38impl AddressAliasTransactionBodyBuilder {
39 /// Creates an instance of AddressAliasTransactionBodyBuilder from binary payload.
40 /// payload: Byte payload to use to serialize the object.
41 /// # Returns
42 /// A AddressAliasTransactionBodyBuilder.
43 pub fn from_binary(payload: &[u8]) -> Self {
44 let mut _bytes = payload.to_vec();
45 let namespace_id = NamespaceIdDto::from_binary(&_bytes); // kind:CUSTOM1
46 _bytes = _bytes[namespace_id.get_size()..].to_vec();
47 let address = AddressDto::from_binary(&_bytes); // kind:CUSTOM1
48 _bytes = _bytes[address.get_size()..].to_vec();
49 let alias_action = AliasActionDto::from_binary(&_bytes); // kind:CUSTOM2
50 _bytes = (&_bytes[alias_action.get_size()..]).to_vec();
51 // create object and call.
52 AddressAliasTransactionBodyBuilder { namespace_id, address, alias_action } // TransactionBody
53 }
54
55 /// Gets the size of the type.
56 ///
57 /// Returns:
58 /// A size in bytes.
59 pub fn get_size(&self) -> usize {
60 let mut size = 0;
61 size += self.namespace_id.get_size(); // namespace_id_size;
62 size += self.address.get_size(); // address_size;
63 size += self.alias_action.get_size(); // alias_action_size;
64 size
65 }
66
67 /// Serializes self to bytes.
68 ///
69 /// # Returns
70 /// A Serialized bytes.
71 pub fn serializer(&self) -> Vec<u8> {
72 let mut buf: Vec<u8> = vec![];
73 buf.append(&mut self.namespace_id.serializer()); // kind:CUSTOM
74 buf.append(&mut self.address.serializer()); // kind:CUSTOM
75 buf.append(&mut self.alias_action.serializer()); // kind:CUSTOM
76 buf
77 }
78}
79