forked from TrueCloudLab/frostfs-api-go
[#186] v2/netmap: Add JSON converter for placement policy
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
2b171e1617
commit
e4d94bbe03
4 changed files with 50 additions and 0 deletions
|
@ -34,3 +34,27 @@ func NodeInfoFromJSON(data []byte) (*NodeInfo, error) {
|
|||
|
||||
return NodeInfoFromGRPCMessage(msg), nil
|
||||
}
|
||||
|
||||
func PlacementPolicyToJSON(n *PlacementPolicy) ([]byte, error) {
|
||||
if n == nil {
|
||||
return nil, errEmptyInput
|
||||
}
|
||||
|
||||
msg := PlacementPolicyToGRPCMessage(n)
|
||||
|
||||
return protojson.MarshalOptions{EmitUnpopulated: true}.Marshal(msg)
|
||||
}
|
||||
|
||||
func PlacementPolicyFromJSON(data []byte) (*PlacementPolicy, error) {
|
||||
if len(data) == 0 {
|
||||
return nil, errEmptyInput
|
||||
}
|
||||
|
||||
msg := new(netmap.PlacementPolicy)
|
||||
|
||||
if err := protojson.Unmarshal(data, msg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return PlacementPolicyFromGRPCMessage(msg), nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue