Class: ML_ruby::ML_list

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ ML_list

Returns a new instance of ML_list.



58
59
60
# File 'lib/ml-ruby/ml_data_types.rb', line 58

def initialize payload
  @payload= payload
end

Instance Attribute Details

#payloadObject (readonly)

Returns the value of attribute payload.



57
58
59
# File 'lib/ml-ruby/ml_data_types.rb', line 57

def payload
  @payload
end

Class Method Details

.decode(data) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ml-ruby/ml_data_types.rb', line 67

def self.decode data
  #    puts self.name, data.inspect
  len= ML_int16.decode data
  data= data[len.size..-1]
  result=[]
  len.payload.times do
    elem= @type.decode( data )
  #      puts self.name, elem.to_yaml
    result<< elem
    data= data[elem.size..-1]
  end
  self.new result
end

Instance Method Details

#==(other) ⇒ Object



80
81
82
83
# File 'lib/ml-ruby/ml_data_types.rb', line 80

def == other
  false unless other
  payload  == other.payload
end

#encodeObject



64
65
66
# File 'lib/ml-ruby/ml_data_types.rb', line 64

def encode
  ML_int16.new( @payload.size ).encode + @payload.inject("") {|sum,elem| sum+elem.encode }
end

#sizeObject



61
62
63
# File 'lib/ml-ruby/ml_data_types.rb', line 61

def size
  ML_int16.size + @payload.inject( 0 ) {|sum,elem| sum+elem.size}
end