Class: Etheruby::Encoders::StaticArray
- Defined in:
- lib/etheruby/encoders/arrays.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from Base
Instance Method Summary collapse
- #decode ⇒ Object
- #encode ⇒ Object
-
#initialize(_type, _size, _data) ⇒ StaticArray
constructor
A new instance of StaticArray.
- #to_s ⇒ Object
Constructor Details
#initialize(_type, _size, _data) ⇒ StaticArray
Returns a new instance of StaticArray.
11 12 13 14 15 |
# File 'lib/etheruby/encoders/arrays.rb', line 11 def initialize(_type, _size, _data) super(_data) @type = _type @size = _size end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
9 10 11 |
# File 'lib/etheruby/encoders/arrays.rb', line 9 def size @size end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
9 10 11 |
# File 'lib/etheruby/encoders/arrays.rb', line 9 def type @type end |
Instance Method Details
#decode ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/etheruby/encoders/arrays.rb', line 40 def decode if Etheruby::is_static_type?(type) sub_decode(0, data) else sub_decode(size*32, data[size*2*32..data.length]) end end |
#encode ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/etheruby/encoders/arrays.rb', line 21 def encode if Etheruby::is_static_type? type data.map{ |d| Etheruby::treat_variable(type, d, :encode) }.join else head_x = '' enc_x = '' c_pos = size * 32 data.map { |d| treated = Etheruby::treat_variable(type, d, :encode) {size: treated.length/2, value: treated} }.each { |item| head_x += Uint.new(c_pos).encode c_pos += item[:size] enc_x += item[:value] } head_x + enc_x end end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/etheruby/encoders/arrays.rb', line 17 def to_s encode end |