rfl::Generic
: add support for long (int64)
#333
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While working on code that converts
rfl::Generic
to JSON and back, I found thatreflect-cpp@v0.17.0
does not properly convert int64's through Generic. Namely, Generic is defined as a variant withint
as one option, which causes the JSON parser to cast yyjson values toint
, potentially truncating the number.This change introduces
long
as a variant option under Generic. It is placed beforeint
to prioritize converting numbers as the bigger variant in the JSON parser, as otherwise the parser will indiscriminately match all integers to int. However, this likely has the side effect where all ints are now treated as longs. As a corrective measure,to_int
andto_long
will fall back and static cast from the other type if the variant does not directly match. I was usure of the impact of upgrading the variant's int to long (instead of the proposed implementation of adding a new variant), but perhaps replacing int with long would be cleaner?If an alternative implementation would be better, please let me know!