[#302] pkg/container: Convert nil Attribute to nil message

Document that `Attribute.ToV2` method returns
`nil` when is called on `nil`. Add
corresponding unit test.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-06-08 15:30:27 +03:00 committed by Alex Vanin
parent 1863694b96
commit 8b7a433864
2 changed files with 22 additions and 0 deletions

View file

@ -29,10 +29,17 @@ func (a *Attribute) Value() string {
return (*container.Attribute)(a).GetValue()
}
// NewAttributeFromV2 wraps protocol dependent version of
// Attribute message.
//
// Nil container.Attribute converts to nil.
func NewAttributeFromV2(v *container.Attribute) *Attribute {
return (*Attribute)(v)
}
// ToV2 converts Attribute to v2 Attribute message.
//
// Nil Attribute converts to nil.
func (a *Attribute) ToV2() *container.Attribute {
return (*container.Attribute)(a)
}