Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

API/Parsing & Schema: no 64-bit integer-as-string support and Reflector<std::size_t> bypassed by basic-type Parser/to_schema (forces internal Parser specialization) #170

Backlog

Description

@clockblocker

Part of #138
Popularity: 1/7 corpus consumers (wolf)

Related issues

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 $2^{53}$. reflect-cpp currently has two compounding gaps here:

  1. There is no built-in processor or wrapper to serialize/deserialize 64-bit integers as decimal JSON strings.
  2. Attempting to customize a fundamental arithmetic type via rfl::Reflector<std::size_t> is ignored by Parser_default::to_schema() (and in newer reflect-cpp, also by Parser_default::read()/write() because internal::is_basic_type_v<T> is dispatched before has_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 into namespace rfl::parsing and partially specialize the internal rfl::parsing::Parser<ReaderType, WriterType, std::size_t, ProcessorsType> template directly.

Observed Downstream Workarounds

games-on-whales/wolf (ac2461f6)

  1. Redundant Reflector<std::size_t> superseded by internal rfl::parsing::Parser<..., std::size_t> specialization:
    In src/moonlight-server/events/reflectors.hpp#L205-L243, wolf first added rfl::Reflector<std::size_t> (commit ffab11f4), then discovered in PR #426 (commit df983797, "fix: serialize size_t schema as string") that to_schema still emitted "type": "integer" for session_id and moonlight_session_id in docs/modules/dev/partials/spec.json. wolf had to #include <rfl/parsing/Parser.hpp> and specialize rfl::parsing::Parser directly (leaving Reflector<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
  2. Manual std::string ID fields and std::stoul/std::stoull conversions across REST DTOs:
    Because 64-bit IDs had no ergonomic wire-string serialization, wolf also manually models session_id / client_id as std::string across 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/write checked has_read_reflector<T>/has_write_reflector<T> first, while Parser_default::to_schema() checked std::is_same<U, std::uint64_t>() / std::is_integral<U>() first and did not dispatch to Reflector<T> at all.
  • In current reflect-cpp (include/rfl/parsing/Parser_default.hpp), if constexpr (internal::is_basic_type_v<T>) is checked first in read, write, and to_schema, ahead of has_read_reflector/has_write_reflector — so a user rfl::Reflector<std::size_t> is silently bypassed across all three operations.
  • Furthermore, globally specializing Parser<..., std::size_t> hijacks every std::size_t across 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, and to_schema (fork PR Add opt-in rfl::Int64AsString processor for 64-bit integers as strings #134 rfl::Int64AsString, covering both int64_t and uint64_t/std::size_t), avoiding both global Parser specialization and domain-type wrapper contagion.
  • Clarify (or fix/static_assert) rfl::Reflector<T> precedence vs is_basic_type_v<T> so consumers either have Reflector<T> honored consistently in read/write/to_schema or receive an explicit diagnostic instead of silent schema mismatch.

Upstream Overlap

Activity

  1. added
    known-downstream-workarounds
    on Nov 29, 2026
  2. clockblocker commented on Nov 29, 2026

    @clockblocker
    OwnerAuthor

    Tracking & PR Cross-Reference

    Status: Tier-2 (upstream discussion first) — 64-bit integer-as-string prototypes parked on discuss/ssot.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    known-downstream-workarounds

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions