File tree 1 file changed +9
-10
lines changed
1 file changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -1784,19 +1784,18 @@ func (d *Decimal) UnmarshalBinary(data []byte) error {
1784
1784
1785
1785
// MarshalBinary implements the encoding.BinaryMarshaler interface.
1786
1786
func (d Decimal ) MarshalBinary () (data []byte , err error ) {
1787
- // Write the exponent first since it's a fixed size
1788
- v1 := make ([]byte , 4 )
1789
- binary .BigEndian .PutUint32 (v1 , uint32 (d .exp ))
1790
-
1791
- // Add the value
1792
- var v2 []byte
1793
- if v2 , err = d .value .GobEncode (); err != nil {
1794
- return
1787
+ // exp is written first, but encode value first to know output size
1788
+ var valueData []byte
1789
+ if valueData , err = d .value .GobEncode (); err != nil {
1790
+ return nil , err
1795
1791
}
1796
1792
1793
+ // Write the exponent in front, since it's a fixed size
1794
+ expData := make ([]byte , 4 , len (valueData )+ 4 )
1795
+ binary .BigEndian .PutUint32 (expData , uint32 (d .exp ))
1796
+
1797
1797
// Return the byte array
1798
- data = append (v1 , v2 ... )
1799
- return
1798
+ return append (expData , valueData ... ), nil
1800
1799
}
1801
1800
1802
1801
// Scan implements the sql.Scanner interface for database deserialization.
You can’t perform that action at this time.
0 commit comments