add bitfield merge func

This commit is contained in:
zgfzgf 2020-11-28 21:54:30 +08:00
parent a7ed639c21
commit 253e22d6ea

View File

@ -27,10 +27,11 @@ var bitFieldCmd = &cli.Command{
},
},
Subcommands: []*cli.Command{
bitFieldRunsCmd,
bitFieldStatCmd,
bitFieldEncodeCmd,
bitFieldDecodeCmd,
bitFieldRunsCmd,
bitFieldStatCmd,
bitFieldMergeCmd,
bitFieldIntersectCmd,
bitFieldSubCmd,
},
@ -152,6 +153,36 @@ var bitFieldDecodeCmd = &cli.Command{
},
}
var bitFieldMergeCmd = &cli.Command{
Name: "merge",
Usage: "Merge 2 bitfields",
Description: "Merge 2 bitfields and print the resulting bitfield",
Action: func(cctx *cli.Context) error {
a, err := decode(cctx, 0)
if err != nil {
return err
}
b, err := decode(cctx, 1)
if err != nil {
return err
}
o, err := bitfield.MergeBitFields(a, b)
if err != nil {
return xerrors.Errorf("merge: %w", err)
}
str, err := encode(cctx, o)
if err != nil {
return err
}
fmt.Println(str)
return nil
},
}
var bitFieldIntersectCmd = &cli.Command{
Name: "intersect",
Usage: "Intersect 2 bitfields",