catbuffer_rust/
mosaic_restriction_entry_builder.rs1use super::generator_utils::*;
23use super::mosaic_address_restriction_entry_builder::*;
24use super::mosaic_global_restriction_entry_builder::*;
25use super::mosaic_restriction_entry_type_dto::*;
26use super::state_header_builder::*;
27
28#[derive(Debug, Clone)]
30pub struct MosaicRestrictionEntryBuilder {
31 super_object: StateHeaderBuilder,
33 entry_type: MosaicRestrictionEntryTypeDto,
35 address_entry: Option<MosaicAddressRestrictionEntryBuilder>,
37 global_entry: Option<MosaicGlobalRestrictionEntryBuilder>,
39}
40
41
42impl MosaicRestrictionEntryBuilder {
43 pub fn from_binary(_bytes: &[u8]) -> Self {
48 let super_object = StateHeaderBuilder::from_binary(_bytes);
49 let mut _bytes = _bytes[super_object.get_size()..].to_vec();
50 let entry_type = MosaicRestrictionEntryTypeDto::from_binary(&_bytes); let mut _bytes = _bytes[entry_type.get_size()..].to_vec();
52 let mut address_entry = None;
53 if entry_type == MosaicRestrictionEntryTypeDto::ADDRESS {
54 let raw_address_entry = MosaicAddressRestrictionEntryBuilder::from_binary(&_bytes);
55 _bytes = (&_bytes[raw_address_entry.get_size()..]).to_vec();
56 address_entry = Some(raw_address_entry); }
58 let mut global_entry = None;
59 if entry_type == MosaicRestrictionEntryTypeDto::GLOBAL {
60 let raw_global_entry = MosaicGlobalRestrictionEntryBuilder::from_binary(&_bytes);
61 _bytes = (&_bytes[raw_global_entry.get_size()..]).to_vec();
62 global_entry = Some(raw_global_entry); }
64 MosaicRestrictionEntryBuilder { super_object, entry_type, address_entry, global_entry }
65 }
66
67 pub fn get_entry_type(&self) -> MosaicRestrictionEntryTypeDto {
72 self.entry_type.clone()
73 }
74
75 pub fn get_address_entry(&self) -> Option<MosaicAddressRestrictionEntryBuilder> {
80 if self.entry_type != MosaicRestrictionEntryTypeDto::ADDRESS {
81 panic!("entryType is not set to ADDRESS.")
82 };
83 self.address_entry.clone()
84 }
85
86 pub fn get_global_entry(&self) -> Option<MosaicGlobalRestrictionEntryBuilder> {
91 if self.entry_type != MosaicRestrictionEntryTypeDto::GLOBAL {
92 panic!("entryType is not set to GLOBAL.")
93 };
94 self.global_entry.clone()
95 }
96
97 pub fn get_size(&self) -> usize {
102 let mut size = self.super_object.get_size();
103 size += self.entry_type.get_size(); if self.entry_type == MosaicRestrictionEntryTypeDto::ADDRESS {
105 size += self.address_entry.as_ref().unwrap().get_size(); }
107 if self.entry_type == MosaicRestrictionEntryTypeDto::GLOBAL {
108 size += self.global_entry.as_ref().unwrap().get_size(); }
110 size
111 }
112
113 pub fn serializer(&self) -> Vec<u8> {
118 let mut buf: Vec<u8> = vec![];
119 buf.append(&mut self.super_object.serializer());
120 buf.append(&mut self.entry_type.serializer()); if self.entry_type == MosaicRestrictionEntryTypeDto::ADDRESS {
122 buf.append(&mut self.address_entry.as_ref().unwrap().serializer()); };
124 if self.entry_type == MosaicRestrictionEntryTypeDto::GLOBAL {
125 buf.append(&mut self.global_entry.as_ref().unwrap().serializer()); };
127 buf
128 }
129}
130