-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
marshal: track omitempty state for the entire index path for embedded…
… structs Embedded struct fields are recorded in `fieldInfo` by taking the outer structure's field indices and concatenating the field indices for every field inside the embedded one. Given the example structs, ```go struct Outer { S string *Inner `plist:",omitempty"` } struct Inner { S2 string } ``` We record the indices... ``` Outer.S at [0] Outer.S2 at [1, 0] // Outer.Inner in index 1, Inner.S2 at 0 ``` Because we elided the `typeInfo` for `Outer.Inner`, there was nowhere to store its `omitempty`. We would not want to propagate `omitempty` down to every child, because that would not represent reality. This commit introduces tracking for each index in the index path whether omitempty was set at that level. Now we understand `Outer.S2` like this: ``` + Omit if Outer.Inner is empty | Outer.S2 at [1, 0] ``` I chose to use a 64-bit bitfield to record index indices, so if you nest 64 anonymous embedded structs plist will forget the innermost omitempty flags. To accomplish this with minimal changes, I split `fieldInfo.value` into `value` and `valueForWriting`. `value` no longer populates nil pointers and interfaces, and is safe for reading. `valueForWriting` doesn't care about `omitempty`, and does populate nil pointers in the destination. Unfortunately, plist will still populate empty structures for nested anonymous `omitempty` pointers-to-structs during unmarshal. Closes #74
- Loading branch information
Showing
4 changed files
with
163 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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