Class: ML_ruby::ML_message

Inherits:
Object
  • Object
show all
Defined in:
lib/ml-ruby/ml_protocol.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opcode = nil, payload = nil) ⇒ ML_message

Returns a new instance of ML_message.



29
30
31
32
33
34
35
36
37
# File 'lib/ml-ruby/ml_protocol.rb', line 29

def initialize opcode=nil, payload=nil
  if opcode && opcode.is_a?( ML_int16 )
    @opcode= opcode
  elsif opcode
    @opcode= ML_int16.new( opcode )
  end
  @payload= payload if payload
  @size= ML_int32.new( @opcode.size + (payload ? payload.size : 0) ) if opcode
end

Instance Attribute Details

#opcodeObject (readonly)

Returns the value of attribute opcode.



28
29
30
# File 'lib/ml-ruby/ml_protocol.rb', line 28

def opcode
  @opcode
end

#payloadObject (readonly)

Returns the value of attribute payload.



28
29
30
# File 'lib/ml-ruby/ml_protocol.rb', line 28

def payload
  @payload
end

#sizeObject (readonly)

Returns the value of attribute size.



28
29
30
# File 'lib/ml-ruby/ml_protocol.rb', line 28

def size
  @size
end

Instance Method Details

#encodeObject



38
39
40
# File 'lib/ml-ruby/ml_protocol.rb', line 38

def encode
  @size.encode + @opcode.encode + @payload.encode
end