2020-10-19 18:27:38 +00:00
|
|
|
package netmap
|
|
|
|
|
|
|
|
import (
|
|
|
|
netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
|
2020-10-19 19:09:13 +00:00
|
|
|
"google.golang.org/protobuf/encoding/protojson"
|
2020-10-19 18:27:38 +00:00
|
|
|
)
|
|
|
|
|
2020-11-13 08:45:59 +00:00
|
|
|
func (p *PlacementPolicy) MarshalJSON() ([]byte, error) {
|
|
|
|
return protojson.MarshalOptions{
|
|
|
|
EmitUnpopulated: true,
|
|
|
|
}.Marshal(
|
|
|
|
PlacementPolicyToGRPCMessage(p),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PlacementPolicy) UnmarshalJSON(data []byte) error {
|
|
|
|
msg := new(netmap.PlacementPolicy)
|
2020-10-28 12:10:54 +00:00
|
|
|
|
2020-11-13 08:45:59 +00:00
|
|
|
if err := protojson.Unmarshal(data, msg); err != nil {
|
|
|
|
return err
|
2020-10-19 18:27:38 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 08:45:59 +00:00
|
|
|
*p = *PlacementPolicyFromGRPCMessage(msg)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-10-19 18:27:38 +00:00
|
|
|
|
2020-11-13 08:45:59 +00:00
|
|
|
func (f *Filter) MarshalJSON() ([]byte, error) {
|
|
|
|
return protojson.MarshalOptions{
|
|
|
|
EmitUnpopulated: true,
|
|
|
|
}.Marshal(
|
|
|
|
FilterToGRPCMessage(f),
|
|
|
|
)
|
2020-10-19 18:27:38 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 08:45:59 +00:00
|
|
|
func (f *Filter) UnmarshalJSON(data []byte) error {
|
|
|
|
msg := new(netmap.Filter)
|
|
|
|
|
|
|
|
if err := protojson.Unmarshal(data, msg); err != nil {
|
|
|
|
return err
|
2020-10-19 18:27:38 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 08:45:59 +00:00
|
|
|
*f = *FilterFromGRPCMessage(msg)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Selector) MarshalJSON() ([]byte, error) {
|
|
|
|
return protojson.MarshalOptions{
|
|
|
|
EmitUnpopulated: true,
|
|
|
|
}.Marshal(
|
|
|
|
SelectorToGRPCMessage(s),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Selector) UnmarshalJSON(data []byte) error {
|
|
|
|
msg := new(netmap.Selector)
|
2020-10-19 18:27:38 +00:00
|
|
|
|
2020-10-19 19:09:13 +00:00
|
|
|
if err := protojson.Unmarshal(data, msg); err != nil {
|
2020-11-13 08:45:59 +00:00
|
|
|
return err
|
2020-10-19 18:27:38 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 08:45:59 +00:00
|
|
|
*s = *SelectorFromGRPCMessage(msg)
|
|
|
|
|
|
|
|
return nil
|
2020-10-19 18:27:38 +00:00
|
|
|
}
|
2020-10-29 17:13:07 +00:00
|
|
|
|
2020-11-13 08:45:59 +00:00
|
|
|
func (r *Replica) MarshalJSON() ([]byte, error) {
|
|
|
|
return protojson.MarshalOptions{
|
|
|
|
EmitUnpopulated: true,
|
|
|
|
}.Marshal(
|
|
|
|
ReplicaToGRPCMessage(r),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Replica) UnmarshalJSON(data []byte) error {
|
|
|
|
msg := new(netmap.Replica)
|
|
|
|
|
|
|
|
if err := protojson.Unmarshal(data, msg); err != nil {
|
|
|
|
return err
|
2020-10-29 17:13:07 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 08:45:59 +00:00
|
|
|
*r = *ReplicaFromGRPCMessage(msg)
|
2020-10-29 17:13:07 +00:00
|
|
|
|
2020-11-13 08:45:59 +00:00
|
|
|
return nil
|
2020-10-29 17:13:07 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 08:45:59 +00:00
|
|
|
func (a *Attribute) MarshalJSON() ([]byte, error) {
|
|
|
|
return protojson.MarshalOptions{
|
|
|
|
EmitUnpopulated: true,
|
|
|
|
}.Marshal(
|
|
|
|
AttributeToGRPCMessage(a),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *Attribute) UnmarshalJSON(data []byte) error {
|
|
|
|
msg := new(netmap.NodeInfo_Attribute)
|
|
|
|
|
|
|
|
if err := protojson.Unmarshal(data, msg); err != nil {
|
|
|
|
return err
|
2020-10-29 17:13:07 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 08:45:59 +00:00
|
|
|
*a = *AttributeFromGRPCMessage(msg)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ni *NodeInfo) MarshalJSON() ([]byte, error) {
|
|
|
|
return protojson.MarshalOptions{
|
|
|
|
EmitUnpopulated: true,
|
|
|
|
}.Marshal(
|
|
|
|
NodeInfoToGRPCMessage(ni),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ni *NodeInfo) UnmarshalJSON(data []byte) error {
|
|
|
|
msg := new(netmap.NodeInfo)
|
2020-10-29 17:13:07 +00:00
|
|
|
|
|
|
|
if err := protojson.Unmarshal(data, msg); err != nil {
|
2020-11-13 08:45:59 +00:00
|
|
|
return err
|
2020-10-29 17:13:07 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 08:45:59 +00:00
|
|
|
*ni = *NodeInfoFromGRPCMessage(msg)
|
|
|
|
|
|
|
|
return nil
|
2020-10-29 17:13:07 +00:00
|
|
|
}
|
2021-02-17 17:32:23 +00:00
|
|
|
|
|
|
|
func (i *NetworkInfo) MarshalJSON() ([]byte, error) {
|
|
|
|
return protojson.MarshalOptions{
|
|
|
|
EmitUnpopulated: true,
|
|
|
|
}.Marshal(
|
|
|
|
NetworkInfoToGRPCMessage(i),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *NetworkInfo) UnmarshalJSON(data []byte) error {
|
|
|
|
msg := new(netmap.NetworkInfo)
|
|
|
|
|
|
|
|
if err := protojson.Unmarshal(data, msg); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
*i = *NetworkInfoFromGRPCMessage(msg)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|