Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions blobtypes/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright © 2025 Bartłomiej Święcki (byo)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package blobtypes

import "errors"

var (
ErrUnknownBlobType = errors.New("unknown blob type")
ErrValidationFailed = errors.New("blob validation failed")
)
43 changes: 43 additions & 0 deletions blobtypes/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright © 2025 Bartłomiej Święcki (byo)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package blobtypes

import (
"fmt"

"github.com/cinode/go-common/blob"
)

var (
Invalid = blob.NewType(0x00)
Static = blob.NewType(0x01)
DynamicLink = blob.NewType(0x02)
)

var All = map[string]blob.Type{
"Static": Static,
"DynamicLink": DynamicLink,
}

func ToName(t blob.Type) string {
for name, tp := range All {
if tp == t {
return name
}
}
return fmt.Sprintf("Invalid(%d)", t.IDByte())
}
36 changes: 36 additions & 0 deletions blobtypes/list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright © 2025 Bartłomiej Święcki (byo)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package blobtypes

import (
"testing"

"github.com/cinode/go-common/blob"
"github.com/cinode/go-common/picotestify/require"
)

func TestToName(t *testing.T) {
t.Run("valid known types", func(t *testing.T) {
for name, bType := range All {
require.Equal(t, name, ToName(bType))
}
})
t.Run("invalid type", func(t *testing.T) {
require.Equal(t, "Invalid(0)", ToName(Invalid))
require.Equal(t, "Invalid(255)", ToName(blob.NewType(255)))
})
}