[#168] refs: Implement binary/JSON encoders/decoders on Address

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-13 15:58:53 +03:00 committed by Alex Vanin
parent 9325e22871
commit 4ce751f13c
7 changed files with 114 additions and 33 deletions

26
v2/refs/json.go Normal file
View file

@ -0,0 +1,26 @@
package refs
import (
refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc"
"google.golang.org/protobuf/encoding/protojson"
)
func (a *Address) MarshalJSON() ([]byte, error) {
return protojson.MarshalOptions{
EmitUnpopulated: true,
}.Marshal(
AddressToGRPCMessage(a),
)
}
func (a *Address) UnmarshalJSON(data []byte) error {
msg := new(refs.Address)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
*a = *AddressFromGRPCMessage(msg)
return nil
}