Module: CLValueBytesParsers::CLU256BytesParser

Extended by:
CLU256BytesParser
Included in:
CLU256BytesParser, CLu256
Defined in:
lib/serialization/cl_value_bytes_parsers.rb

Instance Method Summary collapse

Instance Method Details

#from_bytes(byte_array) ⇒ Object



179
180
181
# File 'lib/serialization/cl_value_bytes_parsers.rb', line 179

def from_bytes(byte_array)
    byte_array.reverse.inject(0) {|m, b| (m << 8) + b }
end

#to_bytes(value) ⇒ Object



183
184
185
186
187
188
189
190
191
# File 'lib/serialization/cl_value_bytes_parsers.rb', line 183

def to_bytes(value)
  if value < 0 || value > MAX_U256
    "Parameter value '#{value}' is out of range."
  else
    str = value.to_s(16)
    arr = str.scan(/[0-9a-f]{4}/).map { |x| x.to_i(16) }
    packed = arr.pack("n*").unpack("C*").reverse()
  end
end