frostfs-api-go/v2/tombstone/json.go
Leonard Lyubich 6037a26a35 [#226] v2/tombstone: Implement unified message structure with methods
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2020-12-10 18:26:23 +03:00

26 lines
517 B
Go

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