[#259] netmap: Implement JSON encoding for NetworkInfo RPC messages

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-02-17 20:32:23 +03:00 committed by Alex Vanin
parent 276d863fd5
commit 9eda317efe
2 changed files with 32 additions and 0 deletions

View file

@ -124,3 +124,23 @@ func (ni *NodeInfo) UnmarshalJSON(data []byte) error {
return nil
}
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
}