Module: Rlp::Sedes
- Defined in:
- lib/rlp-lite/sedes.rb,
lib/rlp-lite/sedes/list.rb,
lib/rlp-lite/sedes/binary.rb,
lib/rlp-lite/sedes/big_endian_int.rb
Defined Under Namespace
Classes: BigEndianInt, Binary, List
Class Method Summary collapse
-
.big_endian_int ⇒ Rlp::Sedes::BigEndianInt
A utility to use a big-endian, unsigned integer sedes type with unspecified length.
-
.binary ⇒ 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 ⇒ Rlp::Sedes::BigEndianInt
A utility to use a big-endian, unsigned integer sedes type with unspecified length.
43 44 45 |
# File 'lib/rlp-lite/sedes.rb', line 43 def self.big_endian_int @big_endian_int ||= BigEndianInt.new end |
.binary ⇒ Rlp::Sedes::Binary
A utility to use a binary sedes type.
50 51 52 |
# File 'lib/rlp-lite/sedes.rb', line 50 def self.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.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rlp-lite/sedes.rb', line 16 def self.infer( obj ) if is_sedes?( obj.class ) obj.class elsif obj.is_a?(Integer) && obj >= 0 big_endian_int elsif Binary.valid_type?( obj ) ## note: same as obj.is_a?( String ) binary elsif Util.is_list?( obj ) List.new( elements: obj.map { |item| infer( item ) } ) else raise TypeError, "Did not find sedes handling type #{obj.class.name}" end end |
.is_sedes?(obj) ⇒ Boolean
Determines if an object is a sedes object.
35 36 37 |
# File 'lib/rlp-lite/sedes.rb', line 35 def self.is_sedes?(obj) obj.respond_to?(:serialize) && obj.respond_to?(:deserialize) end |