Use arshal flags instead of coder flags #100
Merged
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.
Instead of consulting the flags on the coder via:
consult flags on the call-provided arshal options via:
This avoids unnecessarily peaking at the internals flags
of Encoder or Decoder and also allows us to simplify
some flag checking logic.
For example, the following are all equivalent:
A similar transform can also be done by applying
De Morgan's law to the following:
There should be no behavior changes as a result of this
since the arshal option flags should be an exact
superset of the coder option flags.
There are 6 entry points to the "json" package:
4 of them (Marshal, MarshalWrite, Unmarshal, UnmarshalRead)
obtain a coder from an internal pool,
where the arshal options plumbed down the call stack
is a pointer to the one inside the coder.
Therefore, there is no behavior difference for these 4 calls.
2 of them (MarshalEncode, UnmarshalDecode) take in a
user-provided coder, where there could theoretically
be a difference between the options struct and the coder options.
However, in both functions, we obtain a jsonopts.Struct locally
from an internal pool and then call jsonopts.Struct.CopyCoderOptions
where the coder options are copied from the user-provided coder
into the local jsonopts.Struct. Thus, the options struct that
we plumb down the stack is gauranteed to be a superset of
the options in the user-provided coder.