Module: RLP::Sedes

Defined in:
lib/rlp/sedes.rb,
lib/rlp/sedes/raw.rb,
lib/rlp/sedes/list.rb,
lib/rlp/sedes/binary.rb,
lib/rlp/sedes/serializable.rb,
lib/rlp/sedes/big_endian_int.rb,
lib/rlp/sedes/countable_list.rb

Defined Under Namespace

Modules: Serializable Classes: BigEndianInt, Binary, CountableList, List, Raw

Class Method Summary collapse

Class Method Details

.big_endian_intObject


36
37
38
# File 'lib/rlp/sedes.rb', line 36

def big_endian_int
  @big_endian_int ||= BigEndianInt.new
end

.binaryObject


40
41
42
# File 'lib/rlp/sedes.rb', line 40

def binary
  @binary ||= Binary.new
end

.infer(obj) ⇒ Object

Try to find a sedes objects suitable for a given Ruby object.

The sedes objects considered are `obj`'s class, `big_endian_int` and `binary`. If `obj` is a list, a `RLP::Sedes::List` will be constructed recursively.

Parameters:

  • obj (Object)

    the Ruby object for which to find a sedes object

Raises:

  • (TypeError)

    if no appropriate sedes could be found


23
24
25
26
27
28
29
30
# File 'lib/rlp/sedes.rb', line 23

def infer(obj)
  return obj.class if sedes?(obj.class)
  return big_endian_int if obj.is_a?(Integer) && obj >= 0
  return binary if Binary.valid_type?(obj)
  return List.new(elements: obj.map {|item| infer(item) }) if RLP.list?(obj)

  raise TypeError, "Did not find sedes handling type #{obj.class.name}"
end

.rawObject


44
45
46
# File 'lib/rlp/sedes.rb', line 44

def raw
  @raw ||= Raw.new
end

.sedes?(obj) ⇒ Boolean

Returns:

  • (Boolean)

32
33
34
# File 'lib/rlp/sedes.rb', line 32

def sedes?(obj)
  obj.respond_to?(:serialize) && obj.respond_to?(:deserialize)
end