forked from TrueCloudLab/frostfs-api-go
Fix lint warnings in storage group package
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
304103c6fa
commit
1ae7f9b491
4 changed files with 30 additions and 3 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
sg "github.com/nspcc-dev/neofs-api-go/v2/storagegroup/grpc"
|
||||
)
|
||||
|
||||
// StorageGroupToGRPCMessage converts unified proto structure into grpc structure.
|
||||
func StorageGroupToGRPCMessage(s *StorageGroup) *sg.StorageGroup {
|
||||
if s == nil {
|
||||
return nil
|
||||
|
@ -29,6 +30,7 @@ func StorageGroupToGRPCMessage(s *StorageGroup) *sg.StorageGroup {
|
|||
return m
|
||||
}
|
||||
|
||||
// StorageGroupFromGRPCMessage converts grpc structure into unified proto structure.
|
||||
func StorageGroupFromGRPCMessage(m *sg.StorageGroup) *StorageGroup {
|
||||
if m == nil {
|
||||
return nil
|
||||
|
|
|
@ -7,12 +7,18 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
// SizeField order number from storage group proto definition.
|
||||
SizeField = 1
|
||||
// HashField order number from storage group proto definition.
|
||||
HashField = 2
|
||||
// ExpirationField order number from storage group proto definition.
|
||||
ExpirationField = 3
|
||||
// ObjectIDsField order number from storage group proto definition.
|
||||
ObjectIDsField = 4
|
||||
)
|
||||
|
||||
// StableMarshal marshals unified storage group structure in a protobuf
|
||||
// compatible way without field order shuffle.
|
||||
func (s *StorageGroup) StableMarshal(buf []byte) ([]byte, error) {
|
||||
if s == nil {
|
||||
return []byte{}, nil
|
||||
|
@ -32,21 +38,25 @@ func (s *StorageGroup) StableMarshal(buf []byte) ([]byte, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
offset += n
|
||||
|
||||
n, err = proto.BytesMarshal(HashField, buf[offset:], s.hash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
offset += n
|
||||
|
||||
n, err = proto.UInt64Marshal(ExpirationField, buf[offset:], s.exp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
offset += n
|
||||
|
||||
prefix, _ = proto.NestedStructurePrefix(ObjectIDsField)
|
||||
|
||||
for i := range s.members {
|
||||
offset += binary.PutUvarint(buf[offset:], prefix)
|
||||
|
||||
|
@ -64,6 +74,7 @@ func (s *StorageGroup) StableMarshal(buf []byte) ([]byte, error) {
|
|||
return buf, nil
|
||||
}
|
||||
|
||||
// StableSize of storage group structure marshalled by StableMarshal function.
|
||||
func (s *StorageGroup) StableSize() (size int) {
|
||||
if s == nil {
|
||||
return 0
|
||||
|
@ -74,6 +85,7 @@ func (s *StorageGroup) StableSize() (size int) {
|
|||
size += proto.UInt64Size(ExpirationField, s.exp)
|
||||
|
||||
_, ln := proto.NestedStructurePrefix(ObjectIDsField)
|
||||
|
||||
for i := range s.members {
|
||||
n := s.members[i].StableSize()
|
||||
size += ln + proto.VarUIntSize(uint64(n)) + n
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
func TestStorageGroup_StableMarshal(t *testing.T) {
|
||||
ownerID1 := new(refs.ObjectID)
|
||||
ownerID1.SetValue([]byte("Object ID 1"))
|
||||
|
||||
ownerID2 := new(refs.ObjectID)
|
||||
ownerID2.SetValue([]byte("Object ID 2"))
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ import (
|
|||
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||
)
|
||||
|
||||
// StorageGroup is a unified structure of StorageGroup
|
||||
// message from proto definition.
|
||||
type StorageGroup struct {
|
||||
size uint64
|
||||
|
||||
|
@ -14,6 +16,7 @@ type StorageGroup struct {
|
|||
members []*refs.ObjectID
|
||||
}
|
||||
|
||||
// GetValidationDataSize of unified storage group structure.
|
||||
func (s *StorageGroup) GetValidationDataSize() uint64 {
|
||||
if s != nil {
|
||||
return s.size
|
||||
|
@ -22,12 +25,14 @@ func (s *StorageGroup) GetValidationDataSize() uint64 {
|
|||
return 0
|
||||
}
|
||||
|
||||
// SetValidationDataSize into unified storage group structure.
|
||||
func (s *StorageGroup) SetValidationDataSize(v uint64) {
|
||||
if s != nil {
|
||||
s.size = v
|
||||
}
|
||||
}
|
||||
|
||||
// GetValidationHash of unified storage group structure.
|
||||
func (s *StorageGroup) GetValidationHash() []byte {
|
||||
if s != nil {
|
||||
return s.hash
|
||||
|
@ -36,12 +41,14 @@ func (s *StorageGroup) GetValidationHash() []byte {
|
|||
return nil
|
||||
}
|
||||
|
||||
// SetValidationHash into unified storage group structure.
|
||||
func (s *StorageGroup) SetValidationHash(v []byte) {
|
||||
if s != nil {
|
||||
s.hash = v
|
||||
}
|
||||
}
|
||||
|
||||
// GetExpirationEpoch of unified storage group structure.
|
||||
func (s *StorageGroup) GetExpirationEpoch() uint64 {
|
||||
if s != nil {
|
||||
return s.exp
|
||||
|
@ -50,12 +57,15 @@ func (s *StorageGroup) GetExpirationEpoch() uint64 {
|
|||
return 0
|
||||
}
|
||||
|
||||
// SetExpirationEpoch into unified storage group structure.
|
||||
func (s *StorageGroup) SetExpirationEpoch(v uint64) {
|
||||
if s != nil {
|
||||
s.exp = v
|
||||
}
|
||||
}
|
||||
|
||||
// GetMembers of unified storage group structure. Members are objects of
|
||||
// storage group.
|
||||
func (s *StorageGroup) GetMembers() []*refs.ObjectID {
|
||||
if s != nil {
|
||||
return s.members
|
||||
|
@ -64,6 +74,8 @@ func (s *StorageGroup) GetMembers() []*refs.ObjectID {
|
|||
return nil
|
||||
}
|
||||
|
||||
// SetMembers into unified storage group structure. Members are objects of
|
||||
// storage group.
|
||||
func (s *StorageGroup) SetMembers(v []*refs.ObjectID) {
|
||||
if s != nil {
|
||||
s.members = v
|
||||
|
|
Loading…
Reference in a new issue