frostfs-sdk-go/object/type.go
Evgenii Baidakov 5d3fcd6f55
enums: Remove FromString method of enumerations
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
2023-04-19 14:33:35 +04:00

58 lines
1.2 KiB
Go

package object
import (
"github.com/nspcc-dev/neofs-api-go/v2/object"
)
type Type object.Type
const (
TypeRegular Type = iota
TypeTombstone
TypeStorageGroup
TypeLock
)
func (t Type) ToV2() object.Type {
return object.Type(t)
}
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 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
}