Class: Melos::Struct::Node

Inherits:
Base
  • Object
show all
Defined in:
lib/melos/struct/structs.rb

Constant Summary collapse

STRUCT =
[
  [:node_type, :uint8],
  [:leaf_node,   :select, ->(ctx){ctx[:node_type] == Melos::Constants::NodeType::LEAF},   :class, Melos::Struct::LeafNode], # leaf
  [:parent_node, :select, ->(ctx){ctx[:node_type] == Melos::Constants::NodeType::PARENT}, :class, Melos::Struct::ParentNode] # parent
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#deserialize_select_elem_with_context, #initialize, #raw

Constructor Details

This class inherits a constructor from Melos::Struct::Base

Instance Attribute Details

#leaf_nodeObject (readonly)

Returns the value of attribute leaf_node.



571
572
573
# File 'lib/melos/struct/structs.rb', line 571

def leaf_node
  @leaf_node
end

#node_typeObject (readonly)

Returns the value of attribute node_type.



571
572
573
# File 'lib/melos/struct/structs.rb', line 571

def node_type
  @node_type
end

#parent_nodeObject (readonly)

Returns the value of attribute parent_node.



571
572
573
# File 'lib/melos/struct/structs.rb', line 571

def parent_node
  @parent_node
end

Class Method Details

.new_leaf_node(leaf_node) ⇒ Object



586
587
588
589
590
# File 'lib/melos/struct/structs.rb', line 586

def self.new_leaf_node(leaf_node)
  instance = self.allocate
  instance.new_leaf_node_impl(leaf_node)
  instance
end

.new_parent_node(parent_node) ⇒ Object



592
593
594
595
596
# File 'lib/melos/struct/structs.rb', line 592

def self.new_parent_node(parent_node)
  instance = self.allocate
  instance.new_parent_node_impl(parent_node)
  instance
end

Instance Method Details

#new_leaf_node_impl(leaf_node) ⇒ Object



598
599
600
601
# File 'lib/melos/struct/structs.rb', line 598

def new_leaf_node_impl(leaf_node)
  @node_type = Melos::Constants::NodeType::LEAF
  @leaf_node = leaf_node
end

#new_parent_node_impl(parent_node) ⇒ Object



603
604
605
606
# File 'lib/melos/struct/structs.rb', line 603

def new_parent_node_impl(parent_node)
  @node_type = Melos::Constants::NodeType::PARENT
  @parent_node = parent_node
end

#parent_hash_in_nodeObject



578
579
580
# File 'lib/melos/struct/structs.rb', line 578

def parent_hash_in_node
  @leaf_node&.parent_hash || @parent_node.parent_hash
end

#public_encryption_keyObject



582
583
584
# File 'lib/melos/struct/structs.rb', line 582

def public_encryption_key
  @leaf_node&.encryption_key || @parent_node&.encryption_key
end