Skip to content

Commit

Permalink
rename IsBlobNamespace to ValidateForBlob
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Oct 16, 2024
1 parent 63ec6b6 commit e7b37c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
25 changes: 12 additions & 13 deletions share/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ func (n Namespace) ValidateForData() error {
return nil
}

// // ValidateForBlob checks if the Namespace is valid blob namespace.
func (n Namespace) ValidateForBlob() error {
if err := n.ValidateForData(); err != nil {
return err
}

if !slices.Contains(SupportedBlobNamespaceVersions, n.Version()) {
return fmt.Errorf("blob version %d is not supported", n.Version())
}
return nil
}

// validateVersionSupported returns an error if the version is not supported.
func (n Namespace) validateVersionSupported() error {
if n.Version() != NamespaceVersionZero && n.Version() != NamespaceVersionMax {
Expand Down Expand Up @@ -219,19 +231,6 @@ func (n Namespace) Repeat(times int) []Namespace {
return ns
}

// IsBlobNamespace returns true if this namespace is a valid user-specifiable
// blob namespace.
func (n Namespace) IsBlobNamespace() bool {
if err := n.ValidateForData(); err != nil {
return false
}

if !slices.Contains(SupportedBlobNamespaceVersions, n.Version()) {
return false
}
return true
}

func (n Namespace) Equals(n2 Namespace) bool {
return bytes.Equal(n.data, n2.data)
}
Expand Down
2 changes: 1 addition & 1 deletion share/random_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func RandomBlobNamespace() Namespace {
for {
id := RandomBlobNamespaceID()
namespace := MustNewV0Namespace(id)
if namespace.IsBlobNamespace() {
if err := namespace.ValidateForBlob(); err == nil {
return namespace
}
}
Expand Down

0 comments on commit e7b37c2

Please sign in to comment.