Module: IOStruct::HexInspect

Includes:
InspectBase
Defined in:
lib/iostruct.rb

Constant Summary collapse

HEX_FMTS =
{ 1 => "%2x", 2 => "%4x", 4 => "%8x", 8 => "%16x" }.freeze

Constants included from InspectBase

InspectBase::INT_MASKS

Instance Method Summary collapse

Methods included from InspectBase

#inspect, #to_s, #to_table

Instance Method Details

#format_int(value, size, fname) ⇒ Object

display as unsigned, because signed %x looks ugly: “..f” for -1



221
222
223
224
225
# File 'lib/iostruct.rb', line 221

def format_int(value, size, fname)
  fmt  = HEX_FMTS[size]  || raise("Unsupported Integer size #{size} for field #{fname}")
  mask = INT_MASKS[size] || raise("Unsupported Integer size #{size} for field #{fname}")
  fmt % (value & mask)
end