class FFI::Bitmask
def to_native(query, ctx)
-
(Integer)
- value of a bitmask -
(Integer)
- value of a bitmask
Parameters:
-
ctx
() -- unused
-
query
(Array
) -- -
ctx
() -- unused
-
query
(Symbol, Integer, #to_int
) --
Overloads:
-
to_native(query, ctx)
-
to_native(query, ctx)
def to_native(query, ctx) return 0 if query.nil? flat_query = [query].flatten res = flat_query.inject(0) do |val, o| case o when Symbol v = @kv_map[o] raise ArgumentError, "invalid bitmask value, #{o.inspect}" unless v val | v when Integer val | o when ->(obj) { obj.respond_to?(:to_int) } val | o.to_int else raise ArgumentError, "invalid bitmask value, #{o.inspect}" end end # Take two's complement of positive values bigger than the max value # for the type when native type is signed. if @signed && res >= (1 << (@native_type.size * 8 - 1)) res = -(-res & ((1 << (@native_type.size * 8)) - 1)) end res end