Sha256: 62589c0695688d6568e44ebe89452c69b101c208811127318dbeb0a55e2d2558

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

module Bytepack
  class TypeInfo < Byte
    extend Extensions::CodeValuesHash
      
    hash_codes [-99, Array], # ARRAY
               [-98, SingleTypeArray], # SingleTypeArray
               [-89, Hash], # Hash
               [1, Null], # NULL
               [3, Byte], # TINYINT
               [4, Short], # SMALLINT
               [5, Integer], # INTEGER
               [6, Long], # BIGINT
               [8, Float], # FLOAT
               [9, String], # STRING
               [10, Symbol], # Symbol
               [11, Timestamp], # TIMESTAMP
               [22, Decimal], # DECIMAL
               [25, Varbinary] # VARBINARY
    
    class << self
      def pack(val)
        val = val.is_a?(::Integer) ? val : code_values[val]||CustomData.code_by_struct(val)
        super(val)
      end
      
      def unpack(bytes, offset = 0)
        unpacked = super(bytes, offset)
        unpacked[0] = codes[unpacked[0]]||CustomData.struct_by_code(unpacked[0]) if unpacked[0]
        unpacked
      end
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bytepack-0.0.1 lib/bytepack/type_info.rb