Repository navigation
Add opt-in rfl::Int64AsString processor for 64-bit integers as strings - #134
Open
clockblocker wants to merge 2 commits into
Open
clockblocker wants to merge 2 commits into
clockblocker wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds an opt-in
rfl::Int64AsStringprocessor (matchingrfl::DurationsAsCountandrfl::UnderlyingEnums) that serializes and deserializes 64-bit (and wider) integer fields (int64_t,uint64_t, etc.) as base-10 strings while keeping narrower integers (int32_t,uint32_t, etc.) as native numbers and leaving default behavior 100% unchanged and zero-overhead when unused.include/rfl/Int64AsString.hpp&include/rfl/internal/int64_as_string_v.hpp: Opt-in marker processor + trait supporting nestedrfl::Processors<...>. Exported frominclude/rfl.hpp.include/rfl/parsing/ParserBasicType.hpp: Guarded behindif constexpr (internal::int64_as_string_v<ProcessorsType> && std::is_integral_v<U> && !std::is_same_v<U, bool> && sizeof(U) >= 8):write: formats viastd::to_chars(exact, locale-independent) and emits a string.read: reads a string and parses viastd::from_charswith full syntax and range checks, returningrfl::Erroron empty strings, whitespace, trailing characters, negative values for unsigned types, or overflow.to_schema: emitsschema::Type::String{}for 64-bit integers while leaving narrower integers asInt32/UInt32/Integer.std::optional,std::vector,rfl::Validator(e.g.rfl::Minimum), and other processors (e.g.rfl::SnakeCaseToCamelCase).docs/content/processors.mdand addedtests/json/test_int64_as_string.cpp.Motivation
Lets a single plain C++ struct (using native
int64_t/uint64_t, with no format-specific wrapper types) be shared cleanly across binary/columnar formats (Arrow, Parquet, CBOR, MsgPack) and JavaScript/TypeScript or Protobuf-JSON wire APIs where bare JSON numbers lose precision above2^53 - 1.Verification
-std=c++20 -Wall -Wextra -Wpedantic -Wshadow -Wconversion -Werror) oninclude/rfl/Int64AsString.hppandinclude/rfl/internal/int64_as_string_v.hpp: passed.tests/json/test_int64_as_string.cpp+tests/json/test_integers.cppunder-fsanitize=undefined -fno-sanitize-recover=all -Wall -Werror: 5/5 passed.