[#168] object: Implement binary/JSON encoders/decoders on ShortHeader

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-13 15:26:23 +03:00 committed by Alex Vanin
parent a684da6118
commit ce0d70fa02
4 changed files with 59 additions and 4 deletions

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

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