catbuffer_rust/
height_activity_bucket_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::amount_dto::*;
23use super::generator_utils::*;
24use super::importance_height_dto::*;
25
26/// Account activity bucket.
27#[derive(Debug, Clone)]
28pub struct HeightActivityBucketBuilder {
29    /// Activity start height.
30    start_height: ImportanceHeightDto,
31    /// Total fees paid by account.
32    total_fees_paid: AmountDto,
33    /// Number of times account has been used as a beneficiary.
34    beneficiary_count: u32,
35    /// Raw importance score.
36    raw_score: u64,
37}
38
39
40impl HeightActivityBucketBuilder {
41    /// Creates an instance of HeightActivityBucketBuilder from binary payload.
42    /// payload: Byte payload to use to serialize the object.
43    /// # Returns
44    /// A HeightActivityBucketBuilder.
45    pub fn from_binary(_bytes: &[u8]) -> Self {
46        let start_height = ImportanceHeightDto::from_binary(&_bytes); // kind:CUSTOM1
47        let mut _bytes = _bytes[start_height.get_size()..].to_vec();
48        let total_fees_paid = AmountDto::from_binary(&_bytes); // kind:CUSTOM1
49        let mut _bytes = _bytes[total_fees_paid.get_size()..].to_vec();
50        let buf = fixed_bytes::<4>(&_bytes);
51        let beneficiary_count = u32::from_le_bytes(buf); // kind:SIMPLE
52        let _bytes = (&_bytes[4..]).to_vec();
53        let buf = fixed_bytes::<8>(&_bytes);
54        let raw_score = u64::from_le_bytes(buf); // kind:SIMPLE
55        let _bytes = (&_bytes[8..]).to_vec();
56        HeightActivityBucketBuilder { start_height, total_fees_paid, beneficiary_count, raw_score }
57    }
58
59    /// Gets activity start height.
60    ///
61    /// # Returns
62    /// A Activity start height.
63    pub fn get_start_height(&self) -> ImportanceHeightDto {
64        self.start_height.clone()
65    }
66
67    /// Gets total fees paid by account.
68    ///
69    /// # Returns
70    /// A Total fees paid by account.
71    pub fn get_total_fees_paid(&self) -> AmountDto {
72        self.total_fees_paid.clone()
73    }
74
75    /// Gets number of times account has been used as a beneficiary.
76    ///
77    /// # Returns
78    /// A Number of times account has been used as a beneficiary.
79    pub fn get_beneficiary_count(&self) -> u32 {
80        self.beneficiary_count.clone()
81    }
82
83    /// Gets raw importance score.
84    ///
85    /// # Returns
86    /// A Raw importance score.
87    pub fn get_raw_score(&self) -> u64 {
88        self.raw_score.clone()
89    }
90
91    /// Gets the size of the type.
92    ///
93    /// Returns:
94    /// A size in bytes.
95    pub fn get_size(&self) -> usize {
96        let mut size = 0;
97        size += self.start_height.get_size(); // start_height;
98        size += self.total_fees_paid.get_size(); // total_fees_paid;
99        size += 4; // beneficiary_count;
100        size += 8; // raw_score;
101        size
102    }
103
104    /// Serializes self to bytes.
105    ///
106    /// # Returns
107    /// A Serialized bytes.
108    pub fn serializer(&self) -> Vec<u8> {
109        let mut buf: Vec<u8> = vec![];
110        buf.append(&mut self.start_height.serializer()); // kind:CUSTOM
111        buf.append(&mut self.total_fees_paid.serializer()); // kind:CUSTOM
112        buf.append(&mut self.get_beneficiary_count().to_le_bytes().to_vec()); // kind:SIMPLE
113        buf.append(&mut self.get_raw_score().to_le_bytes().to_vec()); // kind:SIMPLE
114        buf
115    }
116}
117