module RLP::Sedes

Public Class Methods

big_endian_int() click to toggle source
# File lib/rlp/sedes.rb, line 37
def big_endian_int
  @big_endian_int ||= BigEndianInt.new
end
binary() click to toggle source
# File lib/rlp/sedes.rb, line 41
def binary
  @binary ||= Binary.new
end
infer(obj) click to toggle source

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.

@param obj [Object] the Ruby object for which to find a sedes object

@raise [TypeError] if no appropriate sedes could be found

# File lib/rlp/sedes.rb, line 24
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
raw() click to toggle source
# File lib/rlp/sedes.rb, line 45
def raw
  @raw ||= Raw.new
end
sedes?(obj) click to toggle source
# File lib/rlp/sedes.rb, line 33
def sedes?(obj)
  obj.respond_to?(:serialize) && obj.respond_to?(:deserialize)
end