Class: Rlp::Decoder

Inherits:
Object
  • Object
show all
Defined in:
lib/rlp-lite/decoder.rb

Overview

Provides an RLP-decoder.

Instance Method Summary collapse

Instance Method Details

#perform(rlp) ⇒ Object

Decodes an RLP-encoded object.

Parameters:

  • rlp (String)

    an RLP-encoded object.

Returns:

  • (Object)

    the decoded and maybe deserialized object.

Raises:



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rlp-lite/decoder.rb', line 13

def perform( rlp )
  rlp = Util.hex_to_bin( rlp )    if Util.is_hex?( rlp )
  rlp = Util.str_to_bytes( rlp )
  begin
    item, next_start = consume_item( rlp, 0 )
  rescue Exception => e
    raise DecodingError, "Cannot decode rlp string: #{e}"
  end
  raise DecodingError, "RLP string ends with #{rlp.size - next_start} superfluous bytes" if next_start != rlp.size
  return item
end