msgpack icon indicating copy to clipboard operation
msgpack copied to clipboard

Documentation: explain that unexported fields are not encoded/decoded

Open Deleplace opened this issue 3 years ago • 0 comments

Expected Behavior

The documentation should say more explicitly how it handles exported and unexported struct fields.

Current Behavior

The documentation doesn't say much about this (unless I missed the relevant section).

Possible Solution

The documentation would say upfront something like "Due to how visibility rules work in Go, the package msgpack will not access any of your struct's unexported fields (starting with a lowercase) even if they have a proper msgpack struct field tag. To make your field serializable/deserializable, make the fields public (or implement MarshalMsgpack and UnmarshalMsgpack). By default a public field results in a msgpack field name starting with an uppercase, but this can be avoided with a struct field tag. All of this is similar to how the standard library package json works."

Deleplace avatar Oct 11 '21 12:10 Deleplace