Skip to content

Support nested and flattened rfl::TaggedUnion - #82

Open
clockblocker wants to merge 6 commits into
field-aliasfrom
nested-tagged-union
Open

clockblocker wants to merge 6 commits into
field-aliasfrom
nested-tagged-union

Conversation

@clockblocker

Copy link
Copy Markdown
Owner

Summary

Supports multi-level / nested rfl::TaggedUnion dispatch directly (e.g., rfl::TaggedUnion<"type", A, NestedUnion> and rfl::Flatten<rfl::TaggedUnion<...>>), eliminating the real-world need to parse raw JSON twice and duplicate dummy outer discriminator fields on every inner variant struct (observed in hudson-trading/slang-server WCP events and obs-websocket RPC dispatch).

What Changed

  • Nested rfl::TaggedUnion alternatives: rfl::TaggedUnion<"outer", DirectAlt, InnerTaggedUnion> and rfl::Flatten<rfl::TaggedUnion<...>> now work across single-pass read, write, NoExtraFields, and to_schema.
  • Single-pass parsing (FlattenedTaggedUnionParser.hpp): Dispatches cleanly without double-parsing raw input strings; detects conflicting/duplicate discriminators and duplicate fields at compile time.
  • Type traits (is_tagged_union.hpp, has_flattened_tagged_union.hpp): Detects direct and flattened TaggedUnion members across C++20 and C++26 field-name reflection paths.
  • Docs & tests:
    • Updated docs/content/variants_and_tagged_unions.md and docs/content/flatten_structs.md.
    • Added tests/json/test_nested_tagged_union.cpp, tests/generic/test_nested_tagged_union.cpp, and 2 compile-fail tests (nested_tu_duplicate_discriminator.cpp, nested_tu_duplicate_field.cpp).

Verification

  • Full CTest suite (JSON, Generic + compile-fail, YAML, CLI, Env) built with -Wall -Werror: 608/608 tests passed (100%).

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