Skip to content

Add opt-in rfl::Int64AsString processor for 64-bit integers as strings - #134

Open
clockblocker wants to merge 2 commits into
mainfrom
feat-int64-as-string
Open

clockblocker wants to merge 2 commits into
mainfrom
feat-int64-as-string

Conversation

@clockblocker

Copy link
Copy Markdown
Owner

Summary

Adds an opt-in rfl::Int64AsString processor (matching rfl::DurationsAsCount and rfl::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 nested rfl::Processors<...>. Exported from include/rfl.hpp.
  • include/rfl/parsing/ParserBasicType.hpp: Guarded behind if constexpr (internal::int64_as_string_v<ProcessorsType> && std::is_integral_v<U> && !std::is_same_v<U, bool> && sizeof(U) >= 8):
    • write: formats via std::to_chars (exact, locale-independent) and emits a string.
    • read: reads a string and parses via std::from_chars with full syntax and range checks, returning rfl::Error on empty strings, whitespace, trailing characters, negative values for unsigned types, or overflow.
    • to_schema: emits schema::Type::String{} for 64-bit integers while leaving narrower integers as Int32/UInt32/Integer.
    • Composes transparently with std::optional, std::vector, rfl::Validator (e.g. rfl::Minimum), and other processors (e.g. rfl::SnakeCaseToCamelCase).
  • Docs & tests: Documented in docs/content/processors.md and added tests/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 above 2^53 - 1.

Verification

  • Strict standalone header checks (-std=c++20 -Wall -Wextra -Wpedantic -Wshadow -Wconversion -Werror) on include/rfl/Int64AsString.hpp and include/rfl/internal/int64_as_string_v.hpp: passed.
  • tests/json/test_int64_as_string.cpp + tests/json/test_integers.cpp under -fsanitize=undefined -fno-sanitize-recover=all -Wall -Werror: 5/5 passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant