Class: Cborb::Decoding::Types::Map

Inherits:
Type
  • Object
show all
Extended by:
IntegerDecodable
Defined in:
lib/cborb/decoding/types/map.rb

Overview

To represent major type: 5(definite-length)

Defined Under Namespace

Classes: Intermediate

Constant Summary

Constants included from IntegerDecodable

IntegerDecodable::UNPACK_TEMPLATES

Class Method Summary collapse

Methods included from IntegerDecodable

consume_as_integer

Methods inherited from Type

indefinite?

Class Method Details

.accept(im_data, type, value) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/cborb/decoding/types/map.rb', line 20

def self.accept(im_data, type, value)
  im_data.keys_and_values << value
  if im_data.keys_and_values.size == im_data.size
    Hash[*im_data.keys_and_values]
  else
    Cborb::Decoding::State::CONTINUE
  end
end

.decode(state, additional_info) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/cborb/decoding/types/map.rb', line 10

def self.decode(state, additional_info)
  size = consume_as_integer(state, additional_info) * 2

  if size > 0
    state.push_stack(self, Intermediate.new(size, []))
  else
    state.accept_value(self, {})
  end
end