2020-08-17 12:05:32 +00:00
|
|
|
package storagegroup
|
|
|
|
|
|
|
|
import (
|
2020-12-21 07:51:45 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/refs"
|
2021-11-16 17:30:55 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/rpc/message"
|
2020-11-13 14:20:24 +00:00
|
|
|
storagegroup "github.com/nspcc-dev/neofs-api-go/v2/storagegroup/grpc"
|
2021-11-16 17:30:55 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/util/proto"
|
2020-08-17 12:05:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-08-18 07:42:47 +00:00
|
|
|
sizeField = 1
|
|
|
|
hashField = 2
|
|
|
|
expirationField = 3
|
|
|
|
objectIDsField = 4
|
2020-08-17 12:05:32 +00:00
|
|
|
)
|
|
|
|
|
2020-08-17 12:19:36 +00:00
|
|
|
// StableMarshal marshals unified storage group structure in a protobuf
|
|
|
|
// compatible way without field order shuffle.
|
2022-04-05 08:24:34 +00:00
|
|
|
func (s *StorageGroup) StableMarshal(buf []byte) []byte {
|
2020-08-17 12:05:32 +00:00
|
|
|
if s == nil {
|
2022-04-05 08:24:34 +00:00
|
|
|
return []byte{}
|
2020-08-17 12:05:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if buf == nil {
|
|
|
|
buf = make([]byte, s.StableSize())
|
|
|
|
}
|
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
var offset int
|
2020-08-17 12:05:32 +00:00
|
|
|
|
2022-03-12 12:20:19 +00:00
|
|
|
offset += proto.UInt64Marshal(sizeField, buf[offset:], s.size)
|
2022-04-05 08:24:34 +00:00
|
|
|
offset += proto.NestedStructureMarshal(hashField, buf[offset:], s.hash)
|
2022-03-12 12:20:19 +00:00
|
|
|
offset += proto.UInt64Marshal(expirationField, buf[offset:], s.exp)
|
2022-04-05 08:24:34 +00:00
|
|
|
refs.ObjectIDNestedListMarshal(objectIDsField, buf[offset:], s.members)
|
2020-08-17 12:05:32 +00:00
|
|
|
|
2022-04-05 08:24:34 +00:00
|
|
|
return buf
|
2020-08-17 12:05:32 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 12:19:36 +00:00
|
|
|
// StableSize of storage group structure marshalled by StableMarshal function.
|
2020-08-17 12:05:32 +00:00
|
|
|
func (s *StorageGroup) StableSize() (size int) {
|
|
|
|
if s == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-08-18 07:42:47 +00:00
|
|
|
size += proto.UInt64Size(sizeField, s.size)
|
2020-08-20 08:04:16 +00:00
|
|
|
size += proto.NestedStructureSize(hashField, s.hash)
|
2020-08-18 07:42:47 +00:00
|
|
|
size += proto.UInt64Size(expirationField, s.exp)
|
2020-12-21 07:51:45 +00:00
|
|
|
size += refs.ObjectIDNestedListSize(objectIDsField, s.members)
|
2020-08-17 12:05:32 +00:00
|
|
|
|
|
|
|
return size
|
|
|
|
}
|
2020-11-13 14:20:24 +00:00
|
|
|
|
|
|
|
func (s *StorageGroup) Unmarshal(data []byte) error {
|
2021-03-12 12:57:23 +00:00
|
|
|
return message.Unmarshal(s, data, new(storagegroup.StorageGroup))
|
2020-11-13 14:20:24 +00:00
|
|
|
}
|