Class: Etheruby::Encoders::Fixed
Instance Attribute Summary
Attributes inherited from FixedBase
#size_d, #size_i
Attributes inherited from Base
#data
Instance Method Summary
collapse
Methods inherited from FixedBase
#initialize
Methods inherited from Base
#initialize
Instance Method Details
#decode ⇒ Object
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/etheruby/encoders/fixed.rb', line 50
def decode
@data = data[0..63]
int_part = Int.new(data[0..(size_i/4)-1]).decode[0]
dec_part = decode_decimal_representation(data[(size_i / 4)..data.length])
if int_part >= 0
return (dec_part + int_part), 32
else
return -(dec_part + int_part.abs), 32
end
end
|
#encode ⇒ Object
40
41
42
43
44
45
46
47
48
|
# File 'lib/etheruby/encoders/fixed.rb', line 40
def encode
if data >= 0
int_part, dec_part = data.to_i, data - data.to_i
else
int_part, dec_part = data.to_i, (data + data.to_i.abs).abs
end
Int.new(int_part).encode(size_i/4) + \
encode_decimal_representation(dec_part).ljust((256-size_i)/4,'0')
end
|