Module: Cborb::Decoding::Types::IntegerDecodable

Included in:
Array, ByteString, Integer, Map, NegativeInteger, Tag, TextString, UnassignedSimpleValue
Defined in:
lib/cborb/decoding/types/integer_decodable.rb

Overview

In CBOR, The process that decode some bytes as integer is popular. Thus, we modularize that.

Constant Summary collapse

UNPACK_TEMPLATES =
[
  "C".freeze,
  "S>".freeze,
  "I>".freeze,
  "Q>".freeze,
].freeze

Instance Method Summary collapse

Instance Method Details

#consume_as_integer(state, additional_info) ⇒ Integer

Parameters:

Returns:



15
16
17
18
19
20
21
22
# File 'lib/cborb/decoding/types/integer_decodable.rb', line 15

def consume_as_integer(state, additional_info)
  return additional_info if additional_info < 24

  index = additional_info - 24
  bytesize = 2**index

  state.consume(bytesize).unpack(UNPACK_TEMPLATES[index]).first
end