Fix lint warnings in storage group package

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-08-17 15:19:36 +03:00 committed by Stanislav Bogatyrev
parent 304103c6fa
commit 1ae7f9b491
4 changed files with 30 additions and 3 deletions

View file

@ -6,6 +6,7 @@ import (
sg "github.com/nspcc-dev/neofs-api-go/v2/storagegroup/grpc" 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 { func StorageGroupToGRPCMessage(s *StorageGroup) *sg.StorageGroup {
if s == nil { if s == nil {
return nil return nil
@ -29,6 +30,7 @@ func StorageGroupToGRPCMessage(s *StorageGroup) *sg.StorageGroup {
return m return m
} }
// StorageGroupFromGRPCMessage converts grpc structure into unified proto structure.
func StorageGroupFromGRPCMessage(m *sg.StorageGroup) *StorageGroup { func StorageGroupFromGRPCMessage(m *sg.StorageGroup) *StorageGroup {
if m == nil { if m == nil {
return nil return nil

View file

@ -7,12 +7,18 @@ import (
) )
const ( const (
// SizeField order number from storage group proto definition.
SizeField = 1 SizeField = 1
// HashField order number from storage group proto definition.
HashField = 2 HashField = 2
// ExpirationField order number from storage group proto definition.
ExpirationField = 3 ExpirationField = 3
// ObjectIDsField order number from storage group proto definition.
ObjectIDsField = 4 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) { func (s *StorageGroup) StableMarshal(buf []byte) ([]byte, error) {
if s == nil { if s == nil {
return []byte{}, nil return []byte{}, nil
@ -32,21 +38,25 @@ func (s *StorageGroup) StableMarshal(buf []byte) ([]byte, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
offset += n offset += n
n, err = proto.BytesMarshal(HashField, buf[offset:], s.hash) n, err = proto.BytesMarshal(HashField, buf[offset:], s.hash)
if err != nil { if err != nil {
return nil, err return nil, err
} }
offset += n offset += n
n, err = proto.UInt64Marshal(ExpirationField, buf[offset:], s.exp) n, err = proto.UInt64Marshal(ExpirationField, buf[offset:], s.exp)
if err != nil { if err != nil {
return nil, err return nil, err
} }
offset += n offset += n
prefix, _ = proto.NestedStructurePrefix(ObjectIDsField) prefix, _ = proto.NestedStructurePrefix(ObjectIDsField)
for i := range s.members { for i := range s.members {
offset += binary.PutUvarint(buf[offset:], prefix) offset += binary.PutUvarint(buf[offset:], prefix)
@ -64,6 +74,7 @@ func (s *StorageGroup) StableMarshal(buf []byte) ([]byte, error) {
return buf, nil return buf, nil
} }
// StableSize of storage group structure marshalled by StableMarshal function.
func (s *StorageGroup) StableSize() (size int) { func (s *StorageGroup) StableSize() (size int) {
if s == nil { if s == nil {
return 0 return 0
@ -74,6 +85,7 @@ func (s *StorageGroup) StableSize() (size int) {
size += proto.UInt64Size(ExpirationField, s.exp) size += proto.UInt64Size(ExpirationField, s.exp)
_, ln := proto.NestedStructurePrefix(ObjectIDsField) _, ln := proto.NestedStructurePrefix(ObjectIDsField)
for i := range s.members { for i := range s.members {
n := s.members[i].StableSize() n := s.members[i].StableSize()
size += ln + proto.VarUIntSize(uint64(n)) + n size += ln + proto.VarUIntSize(uint64(n)) + n

View file

@ -12,6 +12,7 @@ import (
func TestStorageGroup_StableMarshal(t *testing.T) { func TestStorageGroup_StableMarshal(t *testing.T) {
ownerID1 := new(refs.ObjectID) ownerID1 := new(refs.ObjectID)
ownerID1.SetValue([]byte("Object ID 1")) ownerID1.SetValue([]byte("Object ID 1"))
ownerID2 := new(refs.ObjectID) ownerID2 := new(refs.ObjectID)
ownerID2.SetValue([]byte("Object ID 2")) ownerID2.SetValue([]byte("Object ID 2"))

View file

@ -4,6 +4,8 @@ import (
"github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/nspcc-dev/neofs-api-go/v2/refs"
) )
// StorageGroup is a unified structure of StorageGroup
// message from proto definition.
type StorageGroup struct { type StorageGroup struct {
size uint64 size uint64
@ -14,6 +16,7 @@ type StorageGroup struct {
members []*refs.ObjectID members []*refs.ObjectID
} }
// GetValidationDataSize of unified storage group structure.
func (s *StorageGroup) GetValidationDataSize() uint64 { func (s *StorageGroup) GetValidationDataSize() uint64 {
if s != nil { if s != nil {
return s.size return s.size
@ -22,12 +25,14 @@ func (s *StorageGroup) GetValidationDataSize() uint64 {
return 0 return 0
} }
// SetValidationDataSize into unified storage group structure.
func (s *StorageGroup) SetValidationDataSize(v uint64) { func (s *StorageGroup) SetValidationDataSize(v uint64) {
if s != nil { if s != nil {
s.size = v s.size = v
} }
} }
// GetValidationHash of unified storage group structure.
func (s *StorageGroup) GetValidationHash() []byte { func (s *StorageGroup) GetValidationHash() []byte {
if s != nil { if s != nil {
return s.hash return s.hash
@ -36,12 +41,14 @@ func (s *StorageGroup) GetValidationHash() []byte {
return nil return nil
} }
// SetValidationHash into unified storage group structure.
func (s *StorageGroup) SetValidationHash(v []byte) { func (s *StorageGroup) SetValidationHash(v []byte) {
if s != nil { if s != nil {
s.hash = v s.hash = v
} }
} }
// GetExpirationEpoch of unified storage group structure.
func (s *StorageGroup) GetExpirationEpoch() uint64 { func (s *StorageGroup) GetExpirationEpoch() uint64 {
if s != nil { if s != nil {
return s.exp return s.exp
@ -50,12 +57,15 @@ func (s *StorageGroup) GetExpirationEpoch() uint64 {
return 0 return 0
} }
// SetExpirationEpoch into unified storage group structure.
func (s *StorageGroup) SetExpirationEpoch(v uint64) { func (s *StorageGroup) SetExpirationEpoch(v uint64) {
if s != nil { if s != nil {
s.exp = v s.exp = v
} }
} }
// GetMembers of unified storage group structure. Members are objects of
// storage group.
func (s *StorageGroup) GetMembers() []*refs.ObjectID { func (s *StorageGroup) GetMembers() []*refs.ObjectID {
if s != nil { if s != nil {
return s.members return s.members
@ -64,6 +74,8 @@ func (s *StorageGroup) GetMembers() []*refs.ObjectID {
return nil return nil
} }
// SetMembers into unified storage group structure. Members are objects of
// storage group.
func (s *StorageGroup) SetMembers(v []*refs.ObjectID) { func (s *StorageGroup) SetMembers(v []*refs.ObjectID) {
if s != nil { if s != nil {
s.members = v s.members = v