Skip to content

Convert into a struct or named tuple #7

@sairus7

Description

@sairus7

I want to use this as a packed representation for a structure (or a named tuple) with bool fields.
Can I transform this into such a structure?

@bitflag BitFlagName::UInt32 begin
    flag_x
    flag_y
    flag_z
end

inp = flag_x | flag_y

out1 = (flag_x = true, flag_y = true, flag_z = false)

struct Foo
    flag_x::Bool
    flag_y::Bool
    flag_z::Bool
end

out2 = Foo(true, true, false)

# how can I convert inp into out1 and out2?
do_something1(inp) === out1
do_something2(inp) === out2

And then I need to wrap an array of bitflags into a StructArray with fields stored as BitVectors:

vec = [flag_x, flag_y, flag_x | flag_y]
svec1 = StructVector(vec) 
svec1.flag_x isa BitVector === true
svec1[1] isa BitFlagName == true # or maybe a named tuple?

svec2 = StructVector{Foo}(vec)  
svec2[1] isa Foo # struct
svec2.flag_x isa BitVector === true

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