Module: CBOR

Defined in:
lib/cbor.rb,
lib/cbor/error.rb,
lib/cbor/version.rb

Defined Under Namespace

Modules: Consts Classes: CborError, Dumper, Loader

Constant Summary collapse

VERSION =
"1.2.1"

Class Method Summary collapse

Class Method Details

.dump(val) ⇒ Object



11
12
13
# File 'lib/cbor.rb', line 11

def self.dump(val)
  Dumper.new.dump(val)
end

.load(binary, local_tags = {}) ⇒ Object

Load CBOR-encoded data.

‘binary` can be either a String or an IO object. In both cases the first encoded object will be returned.

Local tags (as a hash of tag => lambda) will only be valid within this method.



21
22
23
24
25
26
27
28
# File 'lib/cbor.rb', line 21

def self.load(binary, local_tags = {})
  if binary.is_a? String
    binary = StringIO.new(binary)
  elsif !binary.respond_to? :read
    raise CborError.new("can only load from String or IO")
  end
  Loader.new(binary, local_tags).load
end

.register_class(klass, tag, &block) ⇒ Object



30
31
32
# File 'lib/cbor.rb', line 30

def self.register_class(klass, tag, &block)
  Dumper.register_class(klass, tag, &block)
end

.register_tag(tag, &block) ⇒ Object



34
35
36
# File 'lib/cbor.rb', line 34

def self.register_tag(tag, &block)
  Loader.register_tag(tag, &block)
end