Sha256: 41c98de94d8413ed5a050b26e9e413945bb06ce7386a0e62eaebfd8090e62c9d

Contents?: true

Size: 609 Bytes

Versions: 3

Compression:

Stored size: 609 Bytes

Contents

module Cborb::Decoding::Types
  # To represent major type: 5(indefinite-length)
  #
  # @see https://tools.ietf.org/html/rfc7049#section-2.2.1
  class IndefiniteMap < Type
    def self.indefinite?
      true
    end

    def self.decode(state, additional_info)
      state.push_stack(self, [])
    end

    def self.accept(im_data, type, value)
      if type == Cborb::Decoding::Types::Break
        raise Cborb::DecodingError, "Invalid indefinite-length map" if im_data.size.odd?
        Hash[*im_data]
      else
        im_data << value
        Cborb::Decoding::State::CONTINUE
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cborb-0.3.0 lib/cborb/decoding/types/indefinite_map.rb
cborb-0.2.0 lib/cborb/decoding/types/indefinite_map.rb
cborb-0.1.0 lib/cborb/decoding/types/indefinite_map.rb