Repository navigation
Add opt-in rfl::DefaultTag<Discriminator, Tag> processor for rfl::TaggedUnion - #129
Open
clockblocker wants to merge 1 commit into
Open
clockblocker wants to merge 1 commit into
clockblocker wants to merge 1 commit into
Conversation
3 of 16 tasks
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::DefaultTag<_discriminator, _default_tag>processor that supplies a default discriminator tag when arfl::TaggedUnion<_discriminator, ...>is deserialized from an object whose_discriminatorfield is absent.include/rfl/DefaultTag.hpp&include/rfl/internal/default_tag.hpp: Supports flat and nestedrfl::Processors<...>bundles, and multipleDefaultTagprocessors with distinct discriminators in the same call.include/rfl/parsing/ParserTaggedUnion.hpp:null, or unknown tags still fail as usual).rfl::NoExtraFieldsand empty-struct alternatives work cleanly.static_assertvalidation: rejects unknown_default_tagvalues (not inPossibleTags), duplicateDefaultTagprocessors for the same discriminator, and incompatiblerfl::NoFieldNamescombinations.docs/content/processors.mdand addedtests/json/test_default_tag.cppandtests/yaml/test_default_tag.cpp.Real-World OSS Motivation
using TargetConfigSchema = rfl::TaggedUnion<"version", v1::TargetConfigV1, v2::TargetConfigV2>;and had to pull in<yaml-cpp/yaml.h>directly to manually parse, mutate theYAML::Node, and pass rawInputVarTypeintorfl::yaml::readsolely to default unversioned configs to v1 incudaq/lib/Target/Yaml/TargetConfigSchema.cpp(L36–40): Withrfl::DefaultTag<"version", "1">insideYamlProcessors, that manualyaml-cpppre-parsing disappears completely.Verification
-Wall -Wextra -Wpedantic -Wshadow -Wconversion -Werror): passed; 0 relative-include errors.static_assertverified for invalid default tag, duplicate discriminator, andNoFieldNames.tests/json/test_default_tag.cpp+tests/yaml/test_default_tag.cppunder-fsanitize=undefined -fno-sanitize-recover=all: 4/4 passed.