Class: Etheruby::Encoders::Byte
- Defined in:
- lib/etheruby/encoders/bytes.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Attributes inherited from Base
Instance Method Summary collapse
- #decode ⇒ Object
- #encode ⇒ Object
-
#initialize(_size, _data) ⇒ Byte
constructor
A new instance of Byte.
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
#size ⇒ Object (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
#decode ⇒ Object
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 |
#encode ⇒ Object
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 |