diff --git a/namespace/id.go b/namespace/id.go index f2ddc7bd..d5dd8e77 100644 --- a/namespace/id.go +++ b/namespace/id.go @@ -1,6 +1,9 @@ package namespace -import "bytes" +import ( + "bytes" + "encoding/hex" +) type ID []byte @@ -28,3 +31,8 @@ func (nid ID) Size() IDSize { func (nid ID) String() string { return string(nid) } + +// HexString returns hexadecimal encoding of nid. +func (nid ID) HexString() string { + return hex.EncodeToString(nid) +} diff --git a/namespace/id_test.go b/namespace/id_test.go new file mode 100644 index 00000000..15919b66 --- /dev/null +++ b/namespace/id_test.go @@ -0,0 +1,12 @@ +package namespace + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestID_HexString(t *testing.T) { + nID := ID("12345678") + require.Equal(t, "3132333435363738", nID.HexString()) +}