From 1ae7f9b4915299aa6a79b4bd5ec628af0212455d Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 17 Aug 2020 15:19:36 +0300 Subject: [PATCH] Fix lint warnings in storage group package Signed-off-by: Alex Vanin --- v2/storagegroup/convert.go | 2 ++ v2/storagegroup/marshal.go | 18 +++++++++++++++--- v2/storagegroup/marshal_test.go | 1 + v2/storagegroup/types.go | 12 ++++++++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/v2/storagegroup/convert.go b/v2/storagegroup/convert.go index 4e45e34..df545f9 100644 --- a/v2/storagegroup/convert.go +++ b/v2/storagegroup/convert.go @@ -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 diff --git a/v2/storagegroup/marshal.go b/v2/storagegroup/marshal.go index 6a655a6..4f30d50 100644 --- a/v2/storagegroup/marshal.go +++ b/v2/storagegroup/marshal.go @@ -7,12 +7,18 @@ import ( ) const ( - SizeField = 1 - HashField = 2 + // 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 = 4 + // 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 diff --git a/v2/storagegroup/marshal_test.go b/v2/storagegroup/marshal_test.go index e0db5c5..b79ed80 100644 --- a/v2/storagegroup/marshal_test.go +++ b/v2/storagegroup/marshal_test.go @@ -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")) diff --git a/v2/storagegroup/types.go b/v2/storagegroup/types.go index 38a09f2..720bbe1 100644 --- a/v2/storagegroup/types.go +++ b/v2/storagegroup/types.go @@ -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