Repository navigation
Description
Part of #138
Popularity: 1/7 corpus consumers (wolf)
Related issues
- Directly relates to fork PR Add opt-in rfl::Int64AsString processor for 64-bit integers as strings #134 (Add opt-in
rfl::Int64AsStringprocessor for 64-bit integers as strings, tracked in Triage & Design Notes (Fork-Only): Speculative Schema / Contract APIs #136), fork PR Add rfl::Stringified<T> wrapper for base-10 string-encoded integers #133 (rfl::Stringified<T>), and Map (Lane 4): Schema & Contract Fidelity #88 (Map (Lane 4): Schema & Contract Fidelity).
Problem
JSON/JavaScript clients cannot safely represent 64-bit unsigned integers (such as std::size_t session/client IDs like 10594003729173467913) as JSON numbers without losing precision past reflect-cpp currently has two compounding gaps here:
- There is no built-in processor or wrapper to serialize/deserialize 64-bit integers as decimal JSON strings.
- Attempting to customize a fundamental arithmetic type via
rfl::Reflector<std::size_t>is ignored byParser_default::to_schema()(and in newerreflect-cpp, also byParser_default::read()/write()becauseinternal::is_basic_type_v<T>is dispatched beforehas_read_reflector/has_write_reflector). As a result,rfl::json::to_schema<T>()continues emitting"type": "integer"instead of"type": "string", forcing consumers to reach intonamespace rfl::parsingand partially specialize the internalrfl::parsing::Parser<ReaderType, WriterType, std::size_t, ProcessorsType>template directly.
Observed Downstream Workarounds
games-on-whales/wolf (ac2461f6)
-
Redundant
Reflector<std::size_t>superseded by internalrfl::parsing::Parser<..., std::size_t>specialization:
Insrc/moonlight-server/events/reflectors.hpp#L205-L243,wolffirst addedrfl::Reflector<std::size_t>(commitffab11f4), then discovered in PR#426(commitdf983797, "fix: serialize size_t schema as string") thatto_schemastill emitted"type": "integer"forsession_idandmoonlight_session_idindocs/modules/dev/partials/spec.json.wolfhad to#include <rfl/parsing/Parser.hpp>and specializerfl::parsing::Parserdirectly (leavingReflector<std::size_t>dead right above it):/** * Unsigned long is used by Moonlight as the session ID but JSON doesn't support unsigned integers. */ template <> struct Reflector<std::size_t> { using ReflType = std::string; static ReflType from(const std::size_t &v) { return std::to_string(v); } static std::size_t to(const ReflType &v) { return std::stoull(v); } }; namespace parsing { template <class ReaderType, class WriterType, class ProcessorsType> struct Parser<ReaderType, WriterType, std::size_t, ProcessorsType> { using InputVarType = typename ReaderType::InputVarType; static Result<std::size_t> read(const ReaderType &reader, const InputVarType &var) noexcept { const auto to_size_t = [](const std::string &v) -> Result<std::size_t> { try { return std::stoull(v); } catch (std::exception &e) { return error(e.what()); } }; return Parser<ReaderType, WriterType, std::string, ProcessorsType>::read(reader, var).and_then(to_size_t); } template <class ParentType> static void write(const WriterType &writer, const std::size_t &v, const ParentType &parent) noexcept { Parser<ReaderType, WriterType, std::string, ProcessorsType>::write(writer, std::to_string(v), parent); } static schema::Type to_schema(std::map<std::string, schema::Type> *definitions) { return Parser<ReaderType, WriterType, std::string, ProcessorsType>::to_schema(definitions); } }; } // namespace parsing
-
Manual
std::stringID fields andstd::stoul/std::stoullconversions across REST DTOs:
Because 64-bit IDs had no ergonomic wire-string serialization,wolfalso manually modelssession_id/client_idasstd::stringacross API DTOs (src/moonlight-server/api/api.hpp#L44,#L92-L116,#L158) and parses them manually in handlers (src/moonlight-server/api/endpoints.cpp#L303-L314,#L334,#L356,#L379,#L530,#L583):auto session_id = std::stoul(start_req.value().session_id); ... video_session.session_id = session_id; // Can't be JSON encoded ... audio_session.session_id = session_id; // Can't be JSON encoded
Root Cause in reflect-cpp
- In
v0.21.0,Parser_default::read/writecheckedhas_read_reflector<T>/has_write_reflector<T>first, whileParser_default::to_schema()checkedstd::is_same<U, std::uint64_t>()/std::is_integral<U>()first and did not dispatch toReflector<T>at all. - In current
reflect-cpp(include/rfl/parsing/Parser_default.hpp),if constexpr (internal::is_basic_type_v<T>)is checked first inread,write, andto_schema, ahead ofhas_read_reflector/has_write_reflector— so a userrfl::Reflector<std::size_t>is silently bypassed across all three operations. - Furthermore, globally specializing
Parser<..., std::size_t>hijacks everystd::size_tacross all formats (JSON and TOML alike), rather than scoping stringification to JSON endpoints via a processor.
Suggested Direction
- Ship an opt-in processor for 64-bit integers as JSON strings across
read,write, andto_schema(fork PR Add opt-in rfl::Int64AsString processor for 64-bit integers as strings #134rfl::Int64AsString, covering bothint64_tanduint64_t/std::size_t), avoiding both globalParserspecialization and domain-type wrapper contagion. - Clarify (or fix/static_assert)
rfl::Reflector<T>precedence vsis_basic_type_v<T>so consumers either haveReflector<T>honored consistently inread/write/to_schemaor receive an explicit diagnostic instead of silent schema mismatch.
Upstream Overlap
- Json Schema with Reflector type munich-data-engineering/reflect-cpp#509 / Added support for JSON schemata for the Reflector type; fixes #509 munich-data-engineering/reflect-cpp#527 (closed/fixed via merged PR, partial, post-
wolfv0.21.0) — Addedrfl::Reflector<T>support toParser_default::to_schema()for non-basic types (e.g.,QString), thoughis_basic_type_v<T>still takes precedence overReflector<T>for fundamental integers likestd::size_t. - Bug or possible regression with custom rfl::Reflectors munich-data-engineering/reflect-cpp#609 / Allows usage of custom Reflector for enums types munich-data-engineering/reflect-cpp#621 (closed/fixed enums-only, partial) — Reporter noted custom
Reflectors for enums "and basic types as well" stopped working afterv0.22->v0.23; PR#621restored customReflectorsupport for enums only, leaving basic-typeReflectors bypassed. - Unfiled upstream: 64-bit integer-as-string serialization/processor (
Int64AsString/Stringified<T>) andReflector<T>precedence overis_basic_type_v<T>.
Activity
clockblocker commentedon Nov 29, 2026
Tracking & PR Cross-Reference
Status: Tier-2 (upstream discussion first) — 64-bit integer-as-string prototypes parked on
discuss/ssot.rfl::Int64AsStringopt-in processor (scored 58/100, parked ondiscuss/ssot; see Draft PR Upstream PR Queue (sorted by mergeability score) #191 parked table for open design questions on processor-vs-wrapper scope, strict bare-number rejection, and LP64/LLP64 portability).rfl::Stringified<T>per-field wrapper (branchfeat-stringified-integers).Parser/to_schemabypassingrfl::Reflector<std::size_t>(and other fundamental integer types) remains open and needs upstream design discussion alongside the 64-bit-integer wire representation.