class FFI::Bitmask

def from_native(val, ctx)

Returns:
  • (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)
  list = @kv_map.select { |_, v| v & val != 0 }.keys
  # If there are unmatch flags,
  # return them in an integer,
  # else information can be lost.
  # Similar to Enum behavior.
  remainder = val ^ list.inject(0) do |tmp, o|
    v = @kv_map[o]
    if v then tmp |= v else tmp end
  end
  list.push remainder unless remainder == 0
  return list
end