forked from TrueCloudLab/frostfs-api-go
c8f46f7d97
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
35 lines
598 B
Go
35 lines
598 B
Go
package netmap
|
|
|
|
import (
|
|
netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
)
|
|
|
|
func NodeInfoToJSON(n *NodeInfo) (data []byte) {
|
|
if n == nil {
|
|
return nil
|
|
}
|
|
|
|
msg := NodeInfoToGRPCMessage(n)
|
|
|
|
data, err := protojson.MarshalOptions{EmitUnpopulated: true}.Marshal(msg)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func NodeInfoFromJSON(data []byte) *NodeInfo {
|
|
if len(data) == 0 {
|
|
return nil
|
|
}
|
|
|
|
msg := new(netmap.NodeInfo)
|
|
|
|
if err := protojson.Unmarshal(data, msg); err != nil {
|
|
return nil
|
|
}
|
|
|
|
return NodeInfoFromGRPCMessage(msg)
|
|
}
|