2020-09-10 11:49:17 +00:00
|
|
|
package object
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/object"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Attribute represents v2-compatible object attribute.
|
|
|
|
type Attribute object.Attribute
|
|
|
|
|
|
|
|
// NewAttributeFromV2 wraps v2 Attribute message to Attribute.
|
2021-06-08 15:50:45 +00:00
|
|
|
//
|
|
|
|
// Nil object.Attribute converts to nil.
|
2020-09-10 11:49:17 +00:00
|
|
|
func NewAttributeFromV2(aV2 *object.Attribute) *Attribute {
|
|
|
|
return (*Attribute)(aV2)
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewAttribute creates and initializes blank Attribute.
|
|
|
|
//
|
|
|
|
// Works similar as NewAttributeFromV2(new(Attribute)).
|
|
|
|
func NewAttribute() *Attribute {
|
|
|
|
return NewAttributeFromV2(new(object.Attribute))
|
|
|
|
}
|
|
|
|
|
2020-11-16 08:48:38 +00:00
|
|
|
// Key returns key to the object attribute.
|
|
|
|
func (a *Attribute) Key() string {
|
2020-09-10 11:49:17 +00:00
|
|
|
return (*object.Attribute)(a).GetKey()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetKey sets key to the object attribute.
|
|
|
|
func (a *Attribute) SetKey(v string) {
|
|
|
|
(*object.Attribute)(a).SetKey(v)
|
|
|
|
}
|
|
|
|
|
2020-11-16 08:48:38 +00:00
|
|
|
// Value return value of the object attribute.
|
|
|
|
func (a *Attribute) Value() string {
|
2020-09-10 11:49:17 +00:00
|
|
|
return (*object.Attribute)(a).GetValue()
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetValue sets value of the object attribute.
|
|
|
|
func (a *Attribute) SetValue(v string) {
|
|
|
|
(*object.Attribute)(a).SetValue(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToV2 converts Attribute to v2 Attribute message.
|
2021-06-08 15:50:45 +00:00
|
|
|
//
|
|
|
|
// Nil Attribute converts to nil.
|
2020-09-10 11:49:17 +00:00
|
|
|
func (a *Attribute) ToV2() *object.Attribute {
|
|
|
|
return (*object.Attribute)(a)
|
|
|
|
}
|
2020-11-13 12:31:15 +00:00
|
|
|
|
|
|
|
// Marshal marshals Attribute into a protobuf binary form.
|
|
|
|
//
|
|
|
|
// Buffer is allocated when the argument is empty.
|
|
|
|
// Otherwise, the first buffer is used.
|
2020-11-13 15:04:03 +00:00
|
|
|
func (a *Attribute) Marshal(b ...[]byte) ([]byte, error) {
|
2020-11-13 12:31:15 +00:00
|
|
|
var buf []byte
|
|
|
|
if len(b) > 0 {
|
|
|
|
buf = b[0]
|
|
|
|
}
|
|
|
|
|
2020-11-13 15:04:03 +00:00
|
|
|
return (*object.Attribute)(a).
|
2020-11-13 12:31:15 +00:00
|
|
|
StableMarshal(buf)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmarshal unmarshals protobuf binary representation of Attribute.
|
2020-11-13 15:04:03 +00:00
|
|
|
func (a *Attribute) Unmarshal(data []byte) error {
|
|
|
|
return (*object.Attribute)(a).
|
2020-11-13 12:31:15 +00:00
|
|
|
Unmarshal(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalJSON encodes Attribute to protobuf JSON format.
|
2020-11-13 15:04:03 +00:00
|
|
|
func (a *Attribute) MarshalJSON() ([]byte, error) {
|
|
|
|
return (*object.Attribute)(a).
|
2020-11-13 12:31:15 +00:00
|
|
|
MarshalJSON()
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON decodes Attribute from protobuf JSON format.
|
2020-11-13 15:04:03 +00:00
|
|
|
func (a *Attribute) UnmarshalJSON(data []byte) error {
|
|
|
|
return (*object.Attribute)(a).
|
2020-11-13 12:31:15 +00:00
|
|
|
UnmarshalJSON(data)
|
|
|
|
}
|