There are two ways to define bit fields: bit_fields and bit_fields_typed.
class Struct1 < FFI::BitStruct
layout \
:a, :uint8,
:b, :uint8
bit_fields :a,
:u, 2,
:v, 2,
:w, 1,
:x, 1,
:y, 1,
:z, 1
end
class AccessFlags < FFI::BitStruct
layout \
:flags, :uint8
bit_fields_typed :flags,
revoked: [1, :bool], # Creates revoked? method
expired: [1, :bool], # Creates expired? method
some_string: [4, :string],
reserved: [2, :int]
end
Should we integrate these two methods into one?
class AccessFlags < FFI::BitStruct
layout \
:flags, :uint8
bit_fields :flags,
revoked: [1, :bool], # Creates revoked? method
expired: [1, :bool], # Creates expired? method
some_string: [4, :string],
reserved: [2, :int]
end
In that case, should we also allow a second argument other than an array? (Default is :int)
class AccessFlags < FFI::BitStruct
layout \
:flags, :uint8
bit_fields :flags,
revoked: [1, :bool], # Creates revoked? method
expired: [1, :bool], # Creates expired? method
some_string: [4, :string],
reserved: [2] # or 2
end
ping @djberg96
There are two ways to define bit fields:
bit_fieldsandbit_fields_typed.Should we integrate these two methods into one?
In that case, should we also allow a second argument other than an array? (Default is :int)
ping @djberg96