frostfs-api-go-pogpp/v2/accounting/json.go
Leonard Lyubich 9bebc1247d [#168] accounting: Implement binary/JSON encoders/decoders on Decimal
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2020-11-13 18:07:26 +03:00

26 lines
511 B
Go

package accounting
import (
accounting "github.com/nspcc-dev/neofs-api-go/v2/accounting/grpc"
"google.golang.org/protobuf/encoding/protojson"
)
func (d *Decimal) MarshalJSON() ([]byte, error) {
return protojson.MarshalOptions{
EmitUnpopulated: true,
}.Marshal(
DecimalToGRPCMessage(d),
)
}
func (d *Decimal) UnmarshalJSON(data []byte) error {
msg := new(accounting.Decimal)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
*d = *DecimalFromGRPCMessage(msg)
return nil
}