Module: Klay::Rlp::Sedes
- Defined in:
- lib/klay/rlp/sedes.rb,
lib/klay/rlp/sedes/list.rb,
lib/klay/rlp/sedes/binary.rb,
lib/klay/rlp/sedes/big_endian_int.rb
Overview
Provides serializable and deserializable types (SeDes).
Defined Under Namespace
Classes: BigEndianInt, Binary, List
Class Method Summary collapse
-
.big_endian_int ⇒ Klay::Rlp::Sedes::BigEndianInt
A utility to use a big-endian, unsigned integer sedes type with unspecified length.
-
.binary ⇒ Klay::Rlp::Sedes::Binary
A utility to use a binary sedes type.
-
.infer(obj) ⇒ Object
Tries to find a sedes objects suitable for a given Ruby object.
-
.is_sedes?(obj) ⇒ Boolean
Determines if an object is a sedes object.
Class Method Details
.big_endian_int ⇒ Klay::Rlp::Sedes::BigEndianInt
A utility to use a big-endian, unsigned integer sedes type with unspecified length.
61 62 63 |
# File 'lib/klay/rlp/sedes.rb', line 61 def big_endian_int @big_endian_int ||= BigEndianInt.new end |
.binary ⇒ Klay::Rlp::Sedes::Binary
A utility to use a binary sedes type.
68 69 70 |
# File 'lib/klay/rlp/sedes.rb', line 68 def binary @binary ||= Binary.new end |
.infer(obj) ⇒ Object
Tries 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, an List will be
constructed recursively.
41 42 43 44 45 46 47 |
# File 'lib/klay/rlp/sedes.rb', line 41 def infer(obj) return obj.class if is_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 Util.is_list? obj raise TypeError, "Did not find sedes handling type #{obj.class.name}" end |
.is_sedes?(obj) ⇒ Boolean
Determines if an object is a sedes object.
53 54 55 |
# File 'lib/klay/rlp/sedes.rb', line 53 def is_sedes?(obj) obj.respond_to?(:serialize) && obj.respond_to?(:deserialize) end |