mirror of
https://github.com/shopspring/decimal.git
synced 2024-11-23 12:50:49 +01:00
26 lines
592 B
Go
26 lines
592 B
Go
|
package decimal
|
||
|
|
||
|
import (
|
||
|
"reflect"
|
||
|
|
||
|
"go.mongodb.org/mongo-driver/bson/bsoncodec"
|
||
|
"go.mongodb.org/mongo-driver/bson/bsonrw"
|
||
|
)
|
||
|
|
||
|
func Encoder(encodeContext bsoncodec.EncodeContext, writer bsonrw.ValueWriter, value reflect.Value) error {
|
||
|
return writer.WriteString(value.Interface().(Decimal).String())
|
||
|
}
|
||
|
|
||
|
func Decoder(decodeContext bsoncodec.DecodeContext, reader bsonrw.ValueReader, value reflect.Value) error {
|
||
|
str, err := reader.ReadString()
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
dec, err := NewFromString(str)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
value.Set(reflect.ValueOf(dec))
|
||
|
return nil
|
||
|
}
|