Class: Bytepack::AnyType

Inherits:
Struct
  • Object
show all
Defined in:
lib/bytepack/any_type.rb

Class Method Summary collapse

Methods inherited from Struct

classifyDataType, config, packingDataType, single_type_array?, testpacking

Class Method Details

.pack(val) ⇒ Object



5
6
7
8
# File 'lib/bytepack/any_type.rb', line 5

def pack(val)
  dataType = packingDataType(val)
  TypeInfo.pack(dataType) + dataType.pack(val)
end

.unpack(bytes, offset = 0) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/bytepack/any_type.rb', line 10

def unpack(bytes, offset = 0)
  dataType, offset = *TypeInfo.unpack(bytes, offset)
  if dataType.nil?
    [nil, offset]
  else
    dataType.unpack(bytes, offset)
  end
end