-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add bitmath inspector #128
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, added some comments for small improvements and requests for more unit testing.
Would this ever need to support floats?
condition/number.go
Outdated
func (c inspNumber) Inspect(ctx context.Context, capsule config.Capsule) (output bool, err error) { | ||
var check int64 | ||
if c.Key == "" { | ||
check = int64(binary.BigEndian.Uint64(capsule.Data())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the data isn't a number? I think this needs a unit test, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I switched the parsing to be a little looser with size and format of interpretation by interpreting the byte slice input as a string, then parsing that string to a number using strconv.ParseInt
and return an error when this condition is used without numeric input.
Thanks for the quick review! :) Made some changes including the additional unit tests 👍
Today this inspector would handle floats in a loss-y way by truncating values into integers. There might be a use case for float handling considering that the JSON spec supports decimal notation (specifically arbitrary-precision decimal), but it's implementation should live separately b/c the key operation of bitwise-and masking isn't defined on floats in Go. |
It sounds like two different inspectors (number and bitwise) or this one inspector handles the value differently depending on the type. |
48538e9
to
387b4ca
Compare
With that in mind I've focused this on doing bitmath and then comparing for a non-zero result instead and removed non-bitwise types 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved and changes look good! I added some comments that should be addressed before merging. Could you also change the PR name to be more reflective of the new direction?
Description
This adds a new
bitmath
inspector similar to thestrings
inspector focused on comparison operations with numbers. The supported operations areand
,or
,xor
, andnot
and compare the resulting value with 0.Motivation and Context
Some datasets have field which are bitfield constants where the meaning is best unpacked with bitwise masking to check values and then inserting the meaning into a new field. I don't believe this is possible to check with the other inspectors today.
How Has This Been Tested?
New test cases have been added to cover the new existing operations and it solves for the target use case internally.
Types of changes
Checklist: