2020-10-19 18:23:11 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
container "github.com/nspcc-dev/neofs-api-go/v2/container/grpc"
|
2020-10-19 19:09:13 +00:00
|
|
|
"google.golang.org/protobuf/encoding/protojson"
|
2020-10-19 18:23:11 +00:00
|
|
|
)
|
|
|
|
|
2020-10-19 19:09:13 +00:00
|
|
|
func ContainerToJSON(c *Container) (data []byte) {
|
2020-10-19 18:23:11 +00:00
|
|
|
if c == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := ContainerToGRPCMessage(c)
|
|
|
|
|
2020-10-20 14:57:56 +00:00
|
|
|
data, err := protojson.MarshalOptions{EmitUnpopulated: true}.Marshal(msg)
|
2020-10-19 18:23:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-10-19 19:09:13 +00:00
|
|
|
return
|
2020-10-19 18:23:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ContainerFromJSON(data []byte) *Container {
|
|
|
|
if len(data) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := new(container.Container)
|
|
|
|
|
2020-10-19 19:09:13 +00:00
|
|
|
if err := protojson.Unmarshal(data, msg); err != nil {
|
2020-10-19 18:23:11 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return ContainerFromGRPCMessage(msg)
|
|
|
|
}
|