fix impossibility of a compound choice inside a set/sequence #34
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.
The bug was inspired by N1 codec migration to the new version of MED. As it was discovered, a med::choice with a compound header could not be placed into a med::set or med::sequence as a mandatory member.
It happened because of a process of postponed compound header tag filling. A tag was filled out during a med::choice encode process, just before encoding. That is, by the moment an outer container encoding, the choice header tag remained untouched. Hereby, pre-encode check of all mandatory fields filled caused an error reporting the emptyness of the mandatory field.
The fix moves the compound header tag filling from the encode stage to the earlier stage, namely while choice::ref() API is called.
this change a protocol of working with a choice. Now a user can call med::choice::ref() only once. To reuse a choice / refill some choice member, med::choice::clear() must be called prior to it..
The change also requires to distinguish a context within the ref() call happens. The decode stage, when the choice::ref() API is called by the engine, is the case. During the choice::ref call the header tag was already filled by the recent binary data reading and must not be touched.
To achieve it the new member method bool is_tag_set() was introduced. The new method must be presented in every class/struct where the get_tag() method is defined.