@@ -55,6 +55,7 @@ func NewDecimalFromString(src string) (result *Decimal, err error) {
55
55
return
56
56
}
57
57
58
+ // MarshalMsgpack serializes the Decimal into a MessagePack representation.
58
59
func (decNum * Decimal ) MarshalMsgpack () ([]byte , error ) {
59
60
one := decimal .NewFromInt (1 )
60
61
maxSupportedDecimal := decimal .New (1 , DecimalPrecision ).Sub (one ) // 10^DecimalPrecision - 1
@@ -74,15 +75,17 @@ func (decNum *Decimal) MarshalMsgpack() ([]byte, error) {
74
75
return bcdBuf , nil
75
76
}
76
77
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.
85
80
func (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
+ // +--------+-------------------+------------+===============+
86
89
digits , err := decodeStringFromBCD (b )
87
90
if err != nil {
88
91
return fmt .Errorf ("msgpack: can't decode string from BCD buffer (%x): %w" , b , err )
0 commit comments