class FFI::Bitmask
def from_native(val, ctx)
-
(Array
- list of symbol names corresponding to val, plus an optional remainder if some bits don't match any constant)
Parameters:
-
ctx
() -- unused
-
val
(Integer
) --
def from_native(val, ctx) flags = @kv_map.select { |_, v| v & val != 0 } list = flags.keys # force an unsigned value of the correct size val &= (1 << (@native_type.size * 8)) - 1 if @signed # If there are unmatch flags, # return them in an integer, # else information can be lost. # Similar to Enum behavior. remainder = val ^ flags.values.reduce(0, :|) list.push remainder unless remainder == 0 return list end