proto: publish sg lib, rewrite object
This commit is contained in:
parent
b646388840
commit
0fce8a6ba2
11 changed files with 1011 additions and 696 deletions
43
object/sg.go
43
object/sg.go
|
@ -1,54 +1,31 @@
|
|||
package object
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"sort"
|
||||
|
||||
"github.com/nspcc-dev/neofs-proto/refs"
|
||||
"github.com/nspcc-dev/neofs-proto/storagegroup"
|
||||
)
|
||||
|
||||
// Here are defined getter functions for objects that contain storage group
|
||||
// information.
|
||||
|
||||
type (
|
||||
// IDList is a slice of object ids, that can be sorted.
|
||||
IDList []ID
|
||||
|
||||
// ZoneInfo provides validation info of storage group.
|
||||
ZoneInfo struct {
|
||||
Hash
|
||||
Size uint64
|
||||
}
|
||||
|
||||
// IdentificationInfo provides meta information about storage group.
|
||||
IdentificationInfo struct {
|
||||
SGID
|
||||
CID
|
||||
OwnerID
|
||||
}
|
||||
)
|
||||
|
||||
// Len returns amount of object ids in IDList.
|
||||
func (s IDList) Len() int { return len(s) }
|
||||
|
||||
// Less returns byte comparision between IDList[i] and IDList[j].
|
||||
func (s IDList) Less(i, j int) bool { return bytes.Compare(s[i].Bytes(), s[j].Bytes()) == -1 }
|
||||
|
||||
// Swap swaps element with i and j index in IDList.
|
||||
func (s IDList) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
var _ storagegroup.Provider = (*Object)(nil)
|
||||
|
||||
// Group returns slice of object ids that are part of a storage group.
|
||||
func (m *Object) Group() []ID {
|
||||
func (m *Object) Group() []refs.ObjectID {
|
||||
sgLinks := m.Links(Link_StorageGroup)
|
||||
sort.Sort(IDList(sgLinks))
|
||||
sort.Sort(storagegroup.IDList(sgLinks))
|
||||
return sgLinks
|
||||
}
|
||||
|
||||
// Zones returns validation zones of storage group.
|
||||
func (m *Object) Zones() []ZoneInfo {
|
||||
func (m *Object) Zones() []storagegroup.ZoneInfo {
|
||||
sgInfo, err := m.StorageGroup()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return []ZoneInfo{
|
||||
return []storagegroup.ZoneInfo{
|
||||
{
|
||||
Hash: sgInfo.ValidationHash,
|
||||
Size: sgInfo.ValidationDataSize,
|
||||
|
@ -57,8 +34,8 @@ func (m *Object) Zones() []ZoneInfo {
|
|||
}
|
||||
|
||||
// IDInfo returns meta information about storage group.
|
||||
func (m *Object) IDInfo() *IdentificationInfo {
|
||||
return &IdentificationInfo{
|
||||
func (m *Object) IDInfo() *storagegroup.IdentificationInfo {
|
||||
return &storagegroup.IdentificationInfo{
|
||||
SGID: m.SystemHeader.ID,
|
||||
CID: m.SystemHeader.CID,
|
||||
OwnerID: m.SystemHeader.OwnerID,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue