-
Notifications
You must be signed in to change notification settings - Fork 14
/
type.go
61 lines (50 loc) · 1.32 KB
/
type.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
package object
import (
"github.com/nspcc-dev/neofs-api-go/v2/object"
)
// Type is an enumerator for possible object types.
type Type object.Type
const (
TypeRegular Type = iota
TypeTombstone
TypeStorageGroup
TypeLock
)
// ToV2 converts [Type] to v2 [object.Type].
func (t Type) ToV2() object.Type {
return object.Type(t)
}
// TypeFromV2 converts v2 [object.Type] to [Type].
func TypeFromV2(t object.Type) Type {
return Type(t)
}
// EncodeToString returns string representation of [Type].
//
// String mapping:
// - [TypeTombstone]: TOMBSTONE;
// - [TypeStorageGroup]: STORAGE_GROUP;
// - [TypeLock]: LOCK;
// - [TypeRegular], default: REGULAR.
func (t Type) EncodeToString() string {
return t.ToV2().String()
}
// String implements [fmt.Stringer].
//
// String is designed to be human-readable, and its format MAY differ between
// SDK versions. String MAY return same result as [Type.EncodeToString]. String MUST NOT
// be used to encode ID into NeoFS protocol string.
func (t Type) String() string {
return t.EncodeToString()
}
// DecodeString parses [Type] from a string representation.
// It is a reverse action to EncodeToString().
//
// Returns true if s was parsed successfully.
func (t *Type) DecodeString(s string) bool {
var g object.Type
ok := g.FromString(s)
if ok {
*t = TypeFromV2(g)
}
return ok
}