Seelengrab / FieldFlags.jl

A small package for creating bitfield-like structs.
https://seelengrab.github.io/FieldFlags.jl/
MIT License
11 stars 0 forks source link
bitfields bitpacking julia

FieldFlags.jl

CI Stable CI Nightly docs-stable docs-dev codecov

FieldFlags.jl is a small package for declaring bitfield-like structs, without having to manually mask out bits. For more information, check out the documentation!

julia> using FieldFlags

julia> @bitfield mutable struct Foo
           a:1
           b:2
           _:7
           c:3
       end

# The type only takes up 2 bytes
julia> sizeof(Foo)
2

julia> f = Foo(1,2,3)
Foo(a: true, b: 0x2, c: 0x3)

julia> f.a = 2
2

# Assignments truncate leading bits!
julia> f.a
false