Class: Melos::Struct::FramedContent

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

Constant Summary collapse

STRUCT =
[
  [:group_id, :vec],
  [:epoch, :uint64],
  [:sender, :class, Melos::Struct::Sender],
  [:authenticated_data, :vec],
  [:content_type, :uint8],
  [:application_data, :select, ->(context){context[:content_type] == Melos::Constants::ContentType::APPLICATION}, :vec],
  [:proposal,         :select, ->(context){context[:content_type] == Melos::Constants::ContentType::PROPOSAL}, :class, Melos::Struct::Proposal],
  [:commit,           :select, ->(context){context[:content_type] == Melos::Constants::ContentType::COMMIT}, :class, Melos::Struct::Commit]
]

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

#application_dataObject (readonly)

Returns the value of attribute application_data.



675
676
677
# File 'lib/melos/struct/structs.rb', line 675

def application_data
  @application_data
end

#authenticated_dataObject (readonly)

Returns the value of attribute authenticated_data.



675
676
677
# File 'lib/melos/struct/structs.rb', line 675

def authenticated_data
  @authenticated_data
end

#commitObject (readonly)

Returns the value of attribute commit.



675
676
677
# File 'lib/melos/struct/structs.rb', line 675

def commit
  @commit
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



675
676
677
# File 'lib/melos/struct/structs.rb', line 675

def content_type
  @content_type
end

#epochObject (readonly)

Returns the value of attribute epoch.



675
676
677
# File 'lib/melos/struct/structs.rb', line 675

def epoch
  @epoch
end

#group_idObject (readonly)

Returns the value of attribute group_id.



675
676
677
# File 'lib/melos/struct/structs.rb', line 675

def group_id
  @group_id
end

#proposalObject (readonly)

Returns the value of attribute proposal.



675
676
677
# File 'lib/melos/struct/structs.rb', line 675

def proposal
  @proposal
end

#senderObject (readonly)

Returns the value of attribute sender.



675
676
677
# File 'lib/melos/struct/structs.rb', line 675

def sender
  @sender
end

Class Method Details

.create(group_id:, epoch:, sender:, authenticated_data:, content_type:, content:) ⇒ Object



698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
# File 'lib/melos/struct/structs.rb', line 698

def self.create(group_id:, epoch:, sender:, authenticated_data:, content_type:, content:)
  new_instance = self.allocate
  new_instance.instance_variable_set(:@group_id, group_id)
  new_instance.instance_variable_set(:@epoch, epoch)
  new_instance.instance_variable_set(:@sender, sender)
  new_instance.instance_variable_set(:@authenticated_data, authenticated_data)
  new_instance.instance_variable_set(:@content_type, content_type)
  case content_type
  when Melos::Constants::ContentType::APPLICATION
    new_instance.instance_variable_set(:@application_data, content)
  when Melos::Constants::ContentType::PROPOSAL
    new_instance.instance_variable_set(:@proposal, content)
  when Melos::Constants::ContentType::COMMIT
    new_instance.instance_variable_set(:@commit, content)
  end
  new_instance
end

Instance Method Details

#content_tbs(version, wire_format, group_context) ⇒ Object



687
688
689
690
691
692
693
694
695
696
# File 'lib/melos/struct/structs.rb', line 687

def content_tbs(version, wire_format, group_context)
  buf = [version].pack('S>') + [wire_format].pack('S>') + self.raw
  case sender.sender_type
  when Melos::Constants::SenderType::MEMBER, Melos::Constants::SenderType::NEW_MEMBER_COMMIT
    buf += group_context.raw
  when Melos::Constants::SenderType::EXTERNAL, Melos::Constants::SenderType::NEW_MEMBER_PROPOSAL
    # do nothing
  end
  buf
end