Class: BinaryCodec::Blob
- Inherits:
-
SerializedType
- Object
- SerializedType
- BinaryCodec::Blob
- Defined in:
- lib/binary-codec/types/blob.rb
Instance Attribute Summary
Attributes inherited from SerializedType
Class Method Summary collapse
-
.from(value) ⇒ Blob
Creates a new Blob instance from a value.
-
.from_parser(parser, hint = nil) ⇒ Blob
Creates a Blob instance from a parser.
Instance Method Summary collapse
-
#initialize(byte_buf = nil) ⇒ Blob
constructor
A new instance of Blob.
Methods inherited from SerializedType
from_bytes, from_hex, from_json, get_type_by_name, #to_byte_sink, #to_bytes, #to_hex, #to_json, #value_of
Constructor Details
#initialize(byte_buf = nil) ⇒ Blob
Returns a new instance of Blob.
6 7 8 |
# File 'lib/binary-codec/types/blob.rb', line 6 def initialize(byte_buf = nil) super(byte_buf || []) end |
Class Method Details
.from(value) ⇒ Blob
Creates a new Blob instance from a value.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/binary-codec/types/blob.rb', line 13 def self.from(value) return value if value.is_a?(Blob) if value.is_a?(String) unless valid_hex?(value) raise StandardError, 'Cannot construct Blob from a non-hex string' end return Blob.new(hex_to_bytes(value)) end if value.is_a?(Array) return Blob.new(value) end raise StandardError, 'Cannot construct Blob from value given' end |
.from_parser(parser, hint = nil) ⇒ Blob
Creates a Blob instance from a parser.
34 35 36 |
# File 'lib/binary-codec/types/blob.rb', line 34 def self.from_parser(parser, hint = nil) new(parser.read(hint)) end |