Class: Etheruby::Encoders::DynamicArray

Inherits:
Base
  • Object
show all
Defined in:
lib/etheruby/encoders/arrays.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#data

Instance Method Summary collapse

Constructor Details

#initialize(_type, _data) ⇒ DynamicArray

Returns a new instance of DynamicArray.


69
70
71
72
# File 'lib/etheruby/encoders/arrays.rb', line 69

def initialize(_type, _data)
  super(_data)
  @type = _type
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.


67
68
69
# File 'lib/etheruby/encoders/arrays.rb', line 67

def type
  @type
end

Instance Method Details

#decodeObject


83
84
85
86
87
# File 'lib/etheruby/encoders/arrays.rb', line 83

def decode
  size, taken = Uint.new(data[0..63]).decode
  v, s = StaticArray.new(type, size, data[64..data.length]).decode
  return v, s+taken
end

#encodeObject


78
79
80
81
# File 'lib/etheruby/encoders/arrays.rb', line 78

def encode
  Uint.new(data.count).encode + \
    StaticArray.new(type, data.count, data).encode
end

#to_sObject


74
75
76
# File 'lib/etheruby/encoders/arrays.rb', line 74

def to_s
  encode
end