[#302] pkg/netmap: Convert nil NodeInfo and NodeAttribute to nil message

Document that `NodeAttribute.ToV2` and `NodeInfo.ToV2`
method return `nil` when called on `nil`. Document that
`NodeAttributeFromV2` and `NodeInfoFromV2` functions
return `nil` when called on `nil`. Write corresponding
unit tests.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-06-08 17:47:12 +03:00 committed by Alex Vanin
parent 19cf3c2d0b
commit 05f48d9394
2 changed files with 46 additions and 15 deletions

View file

@ -193,11 +193,15 @@ func NewNodeAttribute() *NodeAttribute {
}
// NodeAttributeFromV2 converts v2 node Attribute to NodeAttribute.
//
// Nil netmap.Attribute converts to nil.
func NewNodeAttributeFromV2(a *netmap.Attribute) *NodeAttribute {
return (*NodeAttribute)(a)
}
// ToV2 converts NodeAttribute to v2 node Attribute.
//
// Nil NodeAttribute converts to nil.
func (a *NodeAttribute) ToV2() *netmap.Attribute {
return (*netmap.Attribute)(a)
}
@ -276,11 +280,15 @@ func NewNodeInfo() *NodeInfo {
}
// NewNodeInfoFromV2 converts v2 NodeInfo to NodeInfo.
//
// Nil netmap.NodeInfo converts to nil.
func NewNodeInfoFromV2(i *netmap.NodeInfo) *NodeInfo {
return (*NodeInfo)(i)
}
// ToV2 converts NodeInfo to v2 NodeInfo.
//
// Nil NodeInfo converts to nil.
func (i *NodeInfo) ToV2() *netmap.NodeInfo {
return (*netmap.NodeInfo)(i)
}