[#231] object: Implement string encode/decode methods on Type

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-12-17 18:46:19 +03:00
parent 0f04087543
commit 53e2756762
3 changed files with 50 additions and 0 deletions

View file

@ -33,3 +33,14 @@ func TypeFromV2(t object.Type) Type {
return TypeRegular
}
}
func (t Type) String() string {
return t.ToV2().String()
}
// TypeFromString parses Type from its string representation.
func TypeFromString(s string) Type {
return TypeFromV2(
object.TypeFromString(s),
)
}

View file

@ -34,3 +34,13 @@ func TestType_ToV2(t *testing.T) {
require.Equal(t, item.t, TypeFromV2(item.t2))
}
}
func TestType_String(t *testing.T) {
for _, typ := range []Type{
TypeRegular,
TypeTombstone,
TypeStorageGroup,
} {
require.Equal(t, typ, TypeFromString(typ.String()))
}
}

29
v2/object/string.go Normal file
View file

@ -0,0 +1,29 @@
package object
const (
typeRegularString = "Regular"
typeTombstoneString = "Tombstone"
typeStorageGroupString = "StorageGroup"
)
func (t Type) String() string {
switch t {
default:
return typeRegularString
case TypeTombstone:
return typeTombstoneString
case TypeStorageGroup:
return typeStorageGroupString
}
}
func TypeFromString(s string) Type {
switch s {
default:
return TypeRegular
case typeTombstoneString:
return TypeTombstone
case typeStorageGroupString:
return TypeStorageGroup
}
}