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

@ -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