forked from vmihailenco/msgpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to prefer text unmarshaler when data type is String
This library currently always prefers to use encoding.BinaryUnmashaler when it's implemented by the target type. This might lead to problems when the type also has a text representation implemented as encoding.TextUnmarshaler. Consider netip.Addr from stdlib as example, which implements both. This library won't be able decode MessagePack containing a string "192.0.2.1" into *netip.Addr because it will attempt to use encoding.BinaryUnmashaler which doesn't expect text representation. Fortunately, MessagePack has distinct string and binary types, so we can check the source data type before choosing the interface to use. This commit changes the behaviour of decoder as follows. When 1) target Go data type implements both BinaryUnmashaler and TextUnmarshaler 2) source MessagePack data type is a string TextUnmarshaler will be preferred over BinaryUnmashaler. This feature is gated behind a Decoder option, because it is potentially backward-incompatible change. See vmihailenco#370
- Loading branch information
Showing
3 changed files
with
117 additions
and
4 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