module Cborb

Constants

VERSION

Public Class Methods

decode(cbor, concatenated: false) click to toggle source

The shorthand to decode CBOR

@param [String] cbor @param [Boolean] concatenated Whether “cbor” param is constructed by concatenated CBOR byte string.

If it's true, this method returns instance of Cborb::Decoding::Concatenated

@return [Object] decoded data(Array, Hash, etc…)

# File lib/cborb.rb, line 43
def decode(cbor, concatenated: false)
  results = Decoding::Concatenated.new
  loop do
    decoder = Decoding::Decoder.new
    decoder.decode(cbor)

    raise Cborb::InvalidByteSequenceError unless decoder.finished?

    results << decoder.result

    if decoder.remaining_bytes.empty?
      break
    elsif !concatenated
      raise Cborb::InvalidByteSequenceError
    end

    cbor = decoder.remaining_bytes
  end

  concatenated ? results : results.first
end

Private Instance Methods

decode(cbor, concatenated: false) click to toggle source

The shorthand to decode CBOR

@param [String] cbor @param [Boolean] concatenated Whether “cbor” param is constructed by concatenated CBOR byte string.

If it's true, this method returns instance of Cborb::Decoding::Concatenated

@return [Object] decoded data(Array, Hash, etc…)

# File lib/cborb.rb, line 43
def decode(cbor, concatenated: false)
  results = Decoding::Concatenated.new
  loop do
    decoder = Decoding::Decoder.new
    decoder.decode(cbor)

    raise Cborb::InvalidByteSequenceError unless decoder.finished?

    results << decoder.result

    if decoder.remaining_bytes.empty?
      break
    elsif !concatenated
      raise Cborb::InvalidByteSequenceError
    end

    cbor = decoder.remaining_bytes
  end

  concatenated ? results : results.first
end