[#172] v2: Use protojson package

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-10-19 22:09:13 +03:00 committed by Alex Vanin
parent fd8e691f61
commit e6035a3249
3 changed files with 21 additions and 26 deletions

View file

@ -1,24 +1,23 @@
package container
import (
"github.com/golang/protobuf/jsonpb"
container "github.com/nspcc-dev/neofs-api-go/v2/container/grpc"
"google.golang.org/protobuf/encoding/protojson"
)
func ContainerToJSON(c *Container) []byte {
func ContainerToJSON(c *Container) (data []byte) {
if c == nil {
return nil
}
msg := ContainerToGRPCMessage(c)
m := jsonpb.Marshaler{}
s, err := m.MarshalToString(msg)
data, err := protojson.Marshal(msg)
if err != nil {
return nil
}
return []byte(s)
return
}
func ContainerFromJSON(data []byte) *Container {
@ -28,7 +27,7 @@ func ContainerFromJSON(data []byte) *Container {
msg := new(container.Container)
if err := jsonpb.UnmarshalString(string(data), msg); err != nil {
if err := protojson.Unmarshal(data, msg); err != nil {
return nil
}