Module: IOStruct::HashFmt

Included in:
IOStruct
Defined in:
lib/iostruct/hash_fmt.rb

Constant Summary collapse

KNOWN_FIELD_TYPES_REVERSED =
{
  'C' => ['uint8_t',  'unsigned char', '_BYTE'],
  'S' => ['uint16_t', 'unsigned short'],
  'I' => ['uint32_t', 'unsigned', 'unsigned int'],
  'L' => ['unsigned long'],
  'Q' => ['uint64_t', 'unsigned long long'],

  'c' => ['int8_t',  'char', 'signed char'],
  's' => ['int16_t', 'short', 'signed short'],
  'i' => ['int32_t', 'int', 'signed', 'signed int'],
  'l' => ['long',    'signed long'],
  'q' => ['int64_t', 'long long', 'signed long long'],

  'd' => ['double'],
  'f' => ['float'],
}.freeze
KNOWN_FIELD_TYPES =
KNOWN_FIELD_TYPES_REVERSED.map { |t, a| a.map { |v| [v, t] } }.flatten.each_slice(2).to_h

Instance Method Summary collapse

Instance Method Details

#get_type_size(typename) ⇒ Object

for external use



25
26
27
28
29
# File 'lib/iostruct/hash_fmt.rb', line 25

def get_type_size(typename)
  type_code = KNOWN_FIELD_TYPES[typename.to_s]
  f_size, = PackFmt::FMTSPEC[type_code]
  f_size
end