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-10-19 19:09:13 +00:00
|
|
|
func NodeInfoToJSON(n *NodeInfo) (data []byte) {
|
2020-10-19 18:27:38 +00:00
|
|
|
if n == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := NodeInfoToGRPCMessage(n)
|
|
|
|
|
2020-10-19 19:09:13 +00:00
|
|
|
data, err := protojson.Marshal(msg)
|
2020-10-19 18:27:38 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-10-19 19:09:13 +00:00
|
|
|
return
|
2020-10-19 18:27:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NodeInfoFromJSON(data []byte) *NodeInfo {
|
|
|
|
if len(data) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := new(netmap.NodeInfo)
|
|
|
|
|
2020-10-19 19:09:13 +00:00
|
|
|
if err := protojson.Unmarshal(data, msg); err != nil {
|
2020-10-19 18:27:38 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return NodeInfoFromGRPCMessage(msg)
|
|
|
|
}
|