Module: Klay::Rlp::Decoder

Extended by:
Decoder
Included in:
Decoder
Defined in:
lib/klay/rlp/decoder.rb

Overview

Provides an RLP-decoder.

Class Method Summary collapse

Instance Method Summary collapse

Class 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:



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/klay/rlp/decoder.rb', line 33

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

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:



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/klay/rlp/decoder.rb', line 33

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