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-11-13 12:21:34 +00:00
|
|
|
func (a *Attribute) MarshalJSON() ([]byte, error) {
|
|
|
|
return protojson.MarshalOptions{
|
|
|
|
EmitUnpopulated: true,
|
|
|
|
}.Marshal(
|
|
|
|
AttributeToGRPCMessage(a),
|
|
|
|
)
|
2020-10-19 18:23:11 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 12:21:34 +00:00
|
|
|
func (a *Attribute) UnmarshalJSON(data []byte) error {
|
|
|
|
msg := new(container.Container_Attribute)
|
2020-10-19 18:23:11 +00:00
|
|
|
|
2020-10-19 19:09:13 +00:00
|
|
|
if err := protojson.Unmarshal(data, msg); err != nil {
|
2020-11-13 12:21:34 +00:00
|
|
|
return err
|
2020-10-19 18:23:11 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 12:21:34 +00:00
|
|
|
*a = *AttributeFromGRPCMessage(msg)
|
|
|
|
|
|
|
|
return nil
|
2020-10-19 18:23:11 +00:00
|
|
|
}
|
2020-11-13 12:14:39 +00:00
|
|
|
|
2020-11-13 12:21:34 +00:00
|
|
|
func (c *Container) MarshalJSON() ([]byte, error) {
|
2020-11-13 12:14:39 +00:00
|
|
|
return protojson.MarshalOptions{
|
|
|
|
EmitUnpopulated: true,
|
|
|
|
}.Marshal(
|
2020-11-13 12:21:34 +00:00
|
|
|
ContainerToGRPCMessage(c),
|
2020-11-13 12:14:39 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:21:34 +00:00
|
|
|
func (c *Container) UnmarshalJSON(data []byte) error {
|
|
|
|
msg := new(container.Container)
|
2020-11-13 12:14:39 +00:00
|
|
|
|
|
|
|
if err := protojson.Unmarshal(data, msg); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:21:34 +00:00
|
|
|
*c = *ContainerFromGRPCMessage(msg)
|
2020-11-13 12:14:39 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|