satellite/metainfo/metabase: avoid magic constant

Change-Id: I4f01e38f67e18ae9cb9845a8e75a987acba66427
This commit is contained in:
Egon Elbre 2021-01-08 19:33:51 +02:00
parent 1709117b0d
commit 24833465e6

View File

@ -52,13 +52,13 @@ func ParseBucketPrefix(prefix BucketPrefix) (BucketLocation, error) {
// ParseCompactBucketPrefix parses BucketPrefix.
func ParseCompactBucketPrefix(compactPrefix []byte) (BucketLocation, error) {
if len(compactPrefix) < 16 {
if len(compactPrefix) < len(uuid.UUID{}) {
return BucketLocation{}, Error.New("invalid prefix %q", compactPrefix)
}
var loc BucketLocation
copy(loc.ProjectID[:], compactPrefix)
loc.BucketName = string(compactPrefix[16:])
loc.BucketName = string(compactPrefix[len(loc.ProjectID):])
return loc, nil
}
@ -69,7 +69,7 @@ func (loc BucketLocation) Prefix() BucketPrefix {
// CompactPrefix converts bucket location into bucket prefix with compact project ID.
func (loc BucketLocation) CompactPrefix() []byte {
xs := make([]byte, 0, 16+len(loc.BucketName))
xs := make([]byte, 0, len(loc.ProjectID)+len(loc.BucketName))
xs = append(xs, loc.ProjectID[:]...)
xs = append(xs, []byte(loc.BucketName)...)
return xs