Add Inner Ring code
This commit is contained in:
parent
dadfd90dcd
commit
b7b5079934
400 changed files with 11420 additions and 8690 deletions
63
pkg/core/object/headers/enum.go
Normal file
63
pkg/core/object/headers/enum.go
Normal file
|
@ -0,0 +1,63 @@
|
|||
package headers
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||
)
|
||||
|
||||
// Header represents object extended header.
|
||||
//
|
||||
// It is a type alias of
|
||||
// github.com/nspcc-dev/neofs-node/pkg/core/object.ExtendedHeader.
|
||||
type Header = object.ExtendedHeader
|
||||
|
||||
// Type represents extended header type.
|
||||
//
|
||||
// It is a type alias of
|
||||
// github.com/nspcc-dev/neofs-node/pkg/core/object.ExtendedHeaderType.
|
||||
type Type = object.ExtendedHeaderType
|
||||
|
||||
const (
|
||||
// this is the only place where this cast is appropriate,
|
||||
// use object.TypeFromUint32 instead.
|
||||
lowerUndefined = Type(iota) // lower unsupported Type value
|
||||
|
||||
// TypeLink is the type of object reference header.
|
||||
TypeLink
|
||||
|
||||
// TypeUser is the of user key-value string header.
|
||||
TypeUser
|
||||
|
||||
// TypeTransform is the type of transformation mark header.
|
||||
TypeTransform
|
||||
|
||||
// TypeTombstone is the type of tombstone mark header.
|
||||
TypeTombstone
|
||||
|
||||
// TypeSessionToken is the type of session token header.
|
||||
TypeSessionToken
|
||||
|
||||
// TypeHomomorphicHash is the type of homomorphic hash header.
|
||||
TypeHomomorphicHash
|
||||
|
||||
// TypePayloadChecksum is the type of payload checksum header.
|
||||
TypePayloadChecksum
|
||||
|
||||
// TypeIntegrity is the type of integrity header.
|
||||
TypeIntegrity
|
||||
|
||||
// TypeStorageGroup is the type of storage group header.
|
||||
TypeStorageGroup
|
||||
|
||||
// TypePublicKey is the type of public key header.
|
||||
TypePublicKey
|
||||
|
||||
upperUndefined // upper unsupported Type value
|
||||
)
|
||||
|
||||
// SupportedType returns true if Type is
|
||||
// the known type of extended header. Each
|
||||
// supported type has named constant.
|
||||
func SupportedType(t Type) bool {
|
||||
return object.TypesGT(t, lowerUndefined) &&
|
||||
object.TypesLT(t, upperUndefined)
|
||||
}
|
34
pkg/core/object/headers/enum_test.go
Normal file
34
pkg/core/object/headers/enum_test.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package headers
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSupportedType(t *testing.T) {
|
||||
for _, typ := range []Type{
|
||||
TypeLink,
|
||||
TypeUser,
|
||||
TypeTransform,
|
||||
TypeTombstone,
|
||||
TypeSessionToken,
|
||||
TypeHomomorphicHash,
|
||||
TypePayloadChecksum,
|
||||
TypeIntegrity,
|
||||
TypeStorageGroup,
|
||||
TypePublicKey,
|
||||
} {
|
||||
require.True(t, SupportedType(typ))
|
||||
}
|
||||
|
||||
for _, typ := range []Type{
|
||||
lowerUndefined,
|
||||
upperUndefined,
|
||||
object.TypeFromUint32(object.TypeToUint32(lowerUndefined) - 1),
|
||||
object.TypeFromUint32(object.TypeToUint32(upperUndefined) + 1),
|
||||
} {
|
||||
require.False(t, SupportedType(typ))
|
||||
}
|
||||
}
|
45
pkg/core/object/headers/user.go
Normal file
45
pkg/core/object/headers/user.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
package headers
|
||||
|
||||
// UserHeader is a value of object extended header
|
||||
// that carries user string key-value pairs.
|
||||
//
|
||||
// All user headers must be type of TypeUser.
|
||||
// All user header must have UserHeader pointer value.
|
||||
type UserHeader struct {
|
||||
key, val string
|
||||
}
|
||||
|
||||
// NewUserHeader creates, initialized and returns
|
||||
// the user extended header.
|
||||
func NewUserHeader(key, val string) *Header {
|
||||
res := new(Header)
|
||||
|
||||
res.SetType(TypeUser)
|
||||
|
||||
res.SetValue(&UserHeader{
|
||||
key: key,
|
||||
val: val,
|
||||
})
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// Key returns the user header key.
|
||||
func (u UserHeader) Key() string {
|
||||
return u.key
|
||||
}
|
||||
|
||||
// SetKey sets the user header key.
|
||||
func (u *UserHeader) SetKey(key string) {
|
||||
u.key = key
|
||||
}
|
||||
|
||||
// Value returns the user header value.
|
||||
func (u UserHeader) Value() string {
|
||||
return u.val
|
||||
}
|
||||
|
||||
// SetValue sets the user header value.
|
||||
func (u *UserHeader) SetValue(val string) {
|
||||
u.val = val
|
||||
}
|
45
pkg/core/object/headers/user_test.go
Normal file
45
pkg/core/object/headers/user_test.go
Normal file
|
@ -0,0 +1,45 @@
|
|||
package headers
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestUserHeader_Key(t *testing.T) {
|
||||
h := new(UserHeader)
|
||||
|
||||
key := "random key"
|
||||
h.SetKey(key)
|
||||
|
||||
require.Equal(t, key, h.Key())
|
||||
}
|
||||
|
||||
func TestUserHeader_Value(t *testing.T) {
|
||||
h := new(UserHeader)
|
||||
|
||||
val := "random value"
|
||||
h.SetValue(val)
|
||||
|
||||
require.Equal(t, val, h.Value())
|
||||
}
|
||||
|
||||
func TestNewUserHeader(t *testing.T) {
|
||||
key := "user key"
|
||||
val := "user val"
|
||||
|
||||
h := NewUserHeader(key, val)
|
||||
|
||||
require.True(t,
|
||||
object.TypesEQ(
|
||||
TypeUser,
|
||||
h.Type(),
|
||||
),
|
||||
)
|
||||
|
||||
uh := h.Value().(*UserHeader)
|
||||
|
||||
require.Equal(t, key, uh.Key())
|
||||
require.Equal(t, val, uh.Value())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue