Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Omit empty simple sturcts Currently, we only omit default values for primitives, interfaces and, pointers. This makes it difficult to determine if a primitive was present in the unpacked message. Whilst unpacking you can determine if a value is present by implementing something similar to standard lib's database/sql.NullInt64 (or any of the other Null* types), but then the "Valid" field will be included when you marshal the struct. To resovle this, we must check if the given struct is simple enough (meaning it doesn't have any hidden fields) to compare to a zero-initialized version of the struct. If it is simple enough, and the provided struct is zero-initialized, and the struct is tagged with "omitempty" we can exclude it from the resulting bytes. * Move and rename omit-empty-zero-struct example * Evaluate zeroness trough IsZero Allows for more control over when a type ought to be seen as a ZeroValue including for types that aren't a struct. * Use type-assertion over reflection.Implements Seems to work the same, requires one less var to live in the namespace, and provides the isZeroer immediately instead of having to do the cast after the Implements check. Co-authored-by: Mathijs van den Worm <[email protected]>
- Loading branch information