[#168] storageGroup: Implement binary/JSON encoders/decoders on SG

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-13 17:20:24 +03:00 committed by Alex Vanin
parent 6456fcf8fa
commit 55948c2ab1
4 changed files with 79 additions and 18 deletions

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

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