Skip to content

Should bit_fields and bit_fields_typed be merged? or not? #12

@kojix2

Description

@kojix2

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions