catbuffer_rust/
normal_block_header_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::block_fee_multiplier_dto::*;
24use super::block_header_builder::*;
25use super::difficulty_dto::*;
26use super::entity_type_dto::*;
27use super::generator_utils::*;
28use super::hash256_dto::*;
29use super::height_dto::*;
30use super::key_dto::*;
31use super::network_type_dto::*;
32use super::signature_dto::*;
33use super::timestamp_dto::*;
34use super::vrf_proof_builder::*;
35
36/// Binary layout for a normal block header.
37#[derive(Debug, Clone)]
38pub struct NormalBlockHeaderBuilder {
39    /// Block header.
40    super_object: BlockHeaderBuilder,
41}
42
43
44impl NormalBlockHeaderBuilder {
45    /// Creates an instance of NormalBlockHeaderBuilder from binary payload.
46    /// payload: Byte payload to use to serialize the object.
47    /// # Returns
48    /// A NormalBlockHeaderBuilder.
49    pub fn from_binary(_bytes: &[u8]) -> Self {
50        let super_object = BlockHeaderBuilder::from_binary(_bytes);
51        let mut _bytes = _bytes[super_object.get_size()..].to_vec();
52        NormalBlockHeaderBuilder { super_object }
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 = self.super_object.get_size();
61        size += 4; // block_header__reserved1;
62        size
63    }
64
65    /// Serializes self to bytes.
66    ///
67    /// # Returns
68    /// A Serialized bytes.
69    pub fn serializer(&self) -> Vec<u8> {
70        let mut buf: Vec<u8> = vec![];
71        buf.append(&mut self.super_object.serializer());
72        buf.append(&mut 4u16.to_le_bytes().to_vec());
73        buf
74    }
75}
76