/
attribute.go
100 lines (86 loc) · 2.95 KB
/
attribute.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package object
import (
"github.com/nspcc-dev/neofs-api-go/v2/object"
)
// Various system attributes.
const (
// AttributeExpirationEpoch is a key to an object attribute that determines
// after what epoch the object becomes expired. Objects that do not have this
// attribute never expire.
//
// Reaction of NeoFS system components to the objects' 'expired' property may
// vary. For example, in the basic scenario, expired objects are auto-deleted
// from the storage. Detailed behavior can be found in the NeoFS Specification.
//
// Note that the value determines exactly the last epoch of the object's
// relevance: for example, with the value N, the object is relevant in epoch N
// and expired in any epoch starting from N+1.
AttributeExpirationEpoch = object.SysAttributeExpEpoch
)
// Attribute represents v2-compatible object attribute.
type Attribute object.Attribute
// NewAttributeFromV2 wraps v2 [object.Attribute] message to [Attribute].
//
// Nil [object.Attribute] converts to nil.
func NewAttributeFromV2(aV2 *object.Attribute) *Attribute {
return (*Attribute)(aV2)
}
// NewAttribute creates and initializes blank [Attribute].
//
// Works similar as NewAttributeFromV2(new(Attribute)).
//
// Defaults:
// - key: "";
// - value: "".
func NewAttribute() *Attribute {
return NewAttributeFromV2(new(object.Attribute))
}
// Key returns key to the object attribute.
func (a *Attribute) Key() string {
return (*object.Attribute)(a).GetKey()
}
// SetKey sets key to the object attribute.
func (a *Attribute) SetKey(v string) {
(*object.Attribute)(a).SetKey(v)
}
// Value return value of the object attribute.
func (a *Attribute) Value() string {
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 [object.Attribute] message.
//
// Nil [Attribute] converts to nil.
//
// The value returned shares memory with the structure itself, so changing it can lead to data corruption.
// Make a copy if you need to change it.
func (a *Attribute) ToV2() *object.Attribute {
return (*object.Attribute)(a)
}
// Marshal marshals [Attribute] into a protobuf binary form.
//
// See also [Attribute.Unmarshal].
func (a *Attribute) Marshal() ([]byte, error) {
return (*object.Attribute)(a).StableMarshal(nil), nil
}
// Unmarshal unmarshals protobuf binary representation of [Attribute].
//
// See also [Attribute.Marshal].
func (a *Attribute) Unmarshal(data []byte) error {
return (*object.Attribute)(a).Unmarshal(data)
}
// MarshalJSON encodes [Attribute] to protobuf JSON format.
//
// See also [Attribute.UnmarshalJSON].
func (a *Attribute) MarshalJSON() ([]byte, error) {
return (*object.Attribute)(a).MarshalJSON()
}
// UnmarshalJSON decodes [Attribute] from protobuf JSON format.
//
// See also [Attribute.MarshalJSON].
func (a *Attribute) UnmarshalJSON(data []byte) error {
return (*object.Attribute)(a).UnmarshalJSON(data)
}