catbuffer_rust/height_activity_buckets_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::height_activity_bucket_builder::*;
24
25/// Account activity buckets.
26#[derive(Debug, Clone)]
27pub struct HeightActivityBucketsBuilder {
28 /// Account activity buckets.
29 buckets: Vec<HeightActivityBucketBuilder>,
30}
31
32
33impl HeightActivityBucketsBuilder {
34 /// Creates an instance of HeightActivityBucketsBuilder from binary payload.
35 /// payload: Byte payload to use to serialize the object.
36 /// # Returns
37 /// A HeightActivityBucketsBuilder.
38 pub fn from_binary(_bytes: &[u8]) -> Self {
39 let mut buckets: Vec<HeightActivityBucketBuilder> = vec![]; // kind:ARRAY
40 let mut _bytes = _bytes.to_vec();
41 for _ in 0..5 {
42 let item = HeightActivityBucketBuilder::from_binary(&_bytes);
43 buckets.push(item.clone());
44 _bytes = (&_bytes[item.get_size()..]).to_vec();
45 }
46 HeightActivityBucketsBuilder { buckets }
47 }
48
49 /// Gets account activity buckets.
50 ///
51 /// # Returns
52 /// A Account activity buckets.
53 pub fn get_buckets(&self) -> Vec<HeightActivityBucketBuilder> {
54 self.buckets.clone() // ARRAY or FILL_ARRAY
55 }
56
57 /// Gets the size of the type.
58 ///
59 /// Returns:
60 /// A size in bytes.
61 pub fn get_size(&self) -> usize {
62 let mut size = 0;
63 size += self.buckets.iter().map(|item| item.get_size()).sum::<usize>(); // array or fill_array;
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 for i in &self.buckets {
74 buf.append(&mut i.serializer()); // kind:ARRAY|FILL_ARRAY
75 }
76 buf
77 }
78}
79