Compare commits

..

1 commit

Author SHA1 Message Date
Egor Seredin
558f392b50
Merge dd34943dc4 into 78289cc844 2024-04-03 14:41:17 +02:00

View file

@ -1796,18 +1796,19 @@ func (d *Decimal) UnmarshalBinary(data []byte) error {
// MarshalBinary implements the encoding.BinaryMarshaler interface.
func (d Decimal) MarshalBinary() (data []byte, err error) {
// exp is written first, but encode value first to know output size
var valueData []byte
if valueData, err = d.value.GobEncode(); err != nil {
return nil, err
// Write the exponent first since it's a fixed size
v1 := make([]byte, 4)
binary.BigEndian.PutUint32(v1, uint32(d.exp))
// Add the value
var v2 []byte
if v2, err = d.value.GobEncode(); err != nil {
return
}
// Write the exponent in front, since it's a fixed size
expData := make([]byte, 4, len(valueData)+4)
binary.BigEndian.PutUint32(expData, uint32(d.exp))
// Return the byte array
return append(expData, valueData...), nil
data = append(v1, v2...)
return
}
// Scan implements the sql.Scanner interface for database deserialization.