Class: Etheruby::Encoders::Byte

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

Instance Attribute Summary collapse

Attributes inherited from Base

#data

Instance Method Summary collapse

Constructor Details

#initialize(_size, _data) ⇒ Byte

Returns a new instance of Byte.



10
11
12
13
# File 'lib/etheruby/encoders/bytes.rb', line 10

def initialize(_size,_data)
  super(_data)
  @size = _size
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



8
9
10
# File 'lib/etheruby/encoders/bytes.rb', line 8

def size
  @size
end

Instance Method Details

#decodeObject



21
22
23
24
# File 'lib/etheruby/encoders/bytes.rb', line 21

def decode
  return data[0..(size*2)-1].split('').each_slice(2).map{ |b| b.join.to_i(16) },
         determinate_closest_padding(size)
end

#encodeObject



15
16
17
18
19
# File 'lib/etheruby/encoders/bytes.rb', line 15

def encode
  data.map{ |b|
    b.to_s(16).rjust(2,'0')
  }.join.ljust(determinate_closest_padding(size)*2, '0')
end