@@ -55,6 +55,7 @@ func NewDecimalFromString(src string) (result *Decimal, err error) {
5555 return
5656}
5757
58+ // MarshalMsgpack serializes the Decimal into a MessagePack representation.
5859func (decNum * Decimal ) MarshalMsgpack () ([]byte , error ) {
5960 one := decimal .NewFromInt (1 )
6061 maxSupportedDecimal := decimal .New (1 , DecimalPrecision ).Sub (one ) // 10^DecimalPrecision - 1
@@ -74,15 +75,17 @@ func (decNum *Decimal) MarshalMsgpack() ([]byte, error) {
7475 return bcdBuf , nil
7576}
7677
77- // Decimal values can be encoded to fixext MessagePack, where buffer
78- // has a fixed length encoded by first byte, and ext MessagePack, where
79- // buffer length is not fixed and encoded by a number in a separate
80- // field:
81- //
82- // +--------+-------------------+------------+===============+
83- // | MP_EXT | length (optional) | MP_DECIMAL | PackedDecimal |
84- // +--------+-------------------+------------+===============+
78+ // UnmarshalMsgpack deserializes a Decimal value from a MessagePack
79+ // representation.
8580func (decNum * Decimal ) UnmarshalMsgpack (b []byte ) error {
81+ // Decimal values can be encoded to fixext MessagePack, where buffer
82+ // has a fixed length encoded by first byte, and ext MessagePack, where
83+ // buffer length is not fixed and encoded by a number in a separate
84+ // field:
85+ //
86+ // +--------+-------------------+------------+===============+
87+ // | MP_EXT | length (optional) | MP_DECIMAL | PackedDecimal |
88+ // +--------+-------------------+------------+===============+
8689 digits , err := decodeStringFromBCD (b )
8790 if err != nil {
8891 return fmt .Errorf ("msgpack: can't decode string from BCD buffer (%x): %w" , b , err )
0 commit comments