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

26 lines
544 B
Go

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
}