Class: Simrpc::Message::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/simrpc/message.rb

Overview

header contains various descriptive properies about a message

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Header

Returns a new instance of Header.



106
107
108
109
110
# File 'lib/simrpc/message.rb', line 106

def initialize(args = {})
   @id     = args[:id].nil?     ? "" : args[:id]
   @type   = args[:type].nil?   ? "" : args[:type]
   @target = args[:target].nil? ? "" : args[:target]
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



104
105
106
# File 'lib/simrpc/message.rb', line 104

def id
  @id
end

#targetObject

Returns the value of attribute target.



104
105
106
# File 'lib/simrpc/message.rb', line 104

def target
  @target
end

#typeObject

Returns the value of attribute type.



104
105
106
# File 'lib/simrpc/message.rb', line 104

def type
  @type
end

Class Method Details

.from_s(data) ⇒ Object



116
117
118
119
120
121
122
# File 'lib/simrpc/message.rb', line 116

def self.from_s(data)
  header = Header.new
  header.id,     data = Formatter::parse_from_formatted_with_fixed_size(8, data)
  header.type,   data = Formatter::parse_from_formatted(data)
  header.target, data = Formatter::parse_from_formatted(data)
  return header
end

Instance Method Details

#to_sObject



112
113
114
# File 'lib/simrpc/message.rb', line 112

def to_s
  Formatter::format_with_fixed_size(8, @id) + Formatter::format_with_size(@type) + Formatter::format_with_size(@target)
end