forked from TrueCloudLab/frostfs-api-go
[#168] accounting: Implement binary/JSON encoders/decoders on Decimal
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
52fae76533
commit
9bebc1247d
6 changed files with 139 additions and 25 deletions
26
v2/accounting/json.go
Normal file
26
v2/accounting/json.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue