Implement hex-to-int function within VRL
Current Vector Version
vector 0.12.2 (v0.12.2 x86_64-unknown-linux-gnu 2021-03-30)
Use-cases
Logging numeric values in hexadecimal format (often without a leading 0x) is a fairly common alternative to decimal format, particularly in high-volume logs in order to reduce IO volume. It would be good to be able to coerce these into integer values for the purpose of aggregation or other numeric manipulations. In my particular case where I'm evaluating vector almost all our numeric values are hex formated, and I was looking to perform summation of some of these values as well as checking if a particular bit within that value is set (I'll open a separate issue for bit logic).
Attempted Solutions
The VRL to_int() function does not currently accept any non-decimal integer format (well, besides timestamps and other base types you have implemented). It would be possible to do this conversion via the lua transform.
Proposal
This could either be implemented as an additional argument to the to_int() function, ie
to_int(value: <string>, base: <integer>) :: <integer>, <error>
or as specific new function along the lines of
hex_to_int(value: <string>) :: <integer>, <error>
References
NA
Thanks @aphelps !
Just to clarify, do you mean that the numbers are just hex encoded such you would want 0xF (or simply F) to be converted to 15? Here I'm distinguishing from the hex being a packed representation of an integer where we'd need to know things like endianness, size, etc.
Noting that we could call this parse_int which I think would match the other parse_X functions.
I like Go's take on this: https://golang.org/pkg/strconv/#ParseInt . We wouldn't need the bitSize parameter.
@jszwedko Thats basically correct, rather than logging a numeric 1234567890 we are logging 499602d2, so no special encoding, byte-order, or anything else involved.