mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-22 20:40:48 +01:00
Compare commits
1 commit
5bc41f90eb
...
558f392b50
Author | SHA1 | Date | |
---|---|---|---|
|
558f392b50 |
1 changed files with 10 additions and 9 deletions
19
decimal.go
19
decimal.go
|
@ -1796,18 +1796,19 @@ func (d *Decimal) UnmarshalBinary(data []byte) error {
|
||||||
|
|
||||||
// MarshalBinary implements the encoding.BinaryMarshaler interface.
|
// MarshalBinary implements the encoding.BinaryMarshaler interface.
|
||||||
func (d Decimal) MarshalBinary() (data []byte, err error) {
|
func (d Decimal) MarshalBinary() (data []byte, err error) {
|
||||||
// exp is written first, but encode value first to know output size
|
// Write the exponent first since it's a fixed size
|
||||||
var valueData []byte
|
v1 := make([]byte, 4)
|
||||||
if valueData, err = d.value.GobEncode(); err != nil {
|
binary.BigEndian.PutUint32(v1, uint32(d.exp))
|
||||||
return nil, err
|
|
||||||
|
// 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 the byte array
|
||||||
return append(expData, valueData...), nil
|
data = append(v1, v2...)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan implements the sql.Scanner interface for database deserialization.
|
// Scan implements the sql.Scanner interface for database deserialization.
|
||||||
|
|
Loading…
Reference in a new issue