Skip to content

Commit

Permalink
chore: unexport PrefixedData8 (#170)
Browse files Browse the repository at this point in the history
Closes #155
  • Loading branch information
rootulp authored Apr 4, 2023
1 parent 8f2171d commit 708cacd
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 66 deletions.
13 changes: 0 additions & 13 deletions namespace/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,3 @@ package namespace
// structure we want: [namespaceID, rawData ...], especially as this type does
// not expect any particular size for the namespace.
type PrefixedData []byte

// PrefixedData8 like PrefixedData is just a slice of bytes. It assumes that the
// slice it represents is at least 8 bytes. This assumption is not enforced by
// the type system though.
type PrefixedData8 []byte

func (d PrefixedData8) NamespaceID() ID {
return ID(d[:8])
}

func (d PrefixedData8) Data() []byte {
return d[8:]
}
119 changes: 66 additions & 53 deletions nmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ import (
"github.com/stretchr/testify/assert"
)

// prefixedData8 like namespace.PrefixedData is just a slice of bytes. It
// assumes that the slice it represents is at least 8 bytes. This assumption is
// not enforced by the type system though.
type prefixedData8 []byte

func (d prefixedData8) NamespaceID() namespace.ID {
return namespace.ID(d[:8])
}

func (d prefixedData8) Data() []byte {
return d[8:]
}

type namespaceDataPair struct {
ID namespace.ID
Data []byte
Expand Down Expand Up @@ -339,140 +352,140 @@ func TestIgnoreMaxNamespace(t *testing.T) {
tests := []struct {
name string
ignoreMaxNamespace bool
pushData []namespace.PrefixedData8
pushData []prefixedData8
wantRootMaxNID namespace.ID
}{
{
"single leaf with MaxNID (ignored)",
true,
[]namespace.PrefixedData8{namespace.PrefixedData8(append(maxNID, []byte("leaf_1")...))},
[]prefixedData8{prefixedData8(append(maxNID, []byte("leaf_1")...))},
maxNID,
},
{
"single leaf with MaxNID (not ignored)",
false,
[]namespace.PrefixedData8{namespace.PrefixedData8(append(maxNID, []byte("leaf_1")...))},
[]prefixedData8{prefixedData8(append(maxNID, []byte("leaf_1")...))},
maxNID,
},
{
"two leaves, one with MaxNID (ignored)",
true,
[]namespace.PrefixedData8{
namespace.PrefixedData8(append(secondNID, []byte("leaf_1")...)),
namespace.PrefixedData8(append(maxNID, []byte("leaf_2")...)),
[]prefixedData8{
prefixedData8(append(secondNID, []byte("leaf_1")...)),
prefixedData8(append(maxNID, []byte("leaf_2")...)),
},
secondNID,
},
{
"two leaves, one with MaxNID (not ignored)",
false,
[]namespace.PrefixedData8{
namespace.PrefixedData8(append(secondNID, []byte("leaf_1")...)),
namespace.PrefixedData8(append(maxNID, []byte("leaf_2")...)),
[]prefixedData8{
prefixedData8(append(secondNID, []byte("leaf_1")...)),
prefixedData8(append(maxNID, []byte("leaf_2")...)),
},
maxNID,
},
{
"two leaves with MaxNID (ignored)",
true,
[]namespace.PrefixedData8{
namespace.PrefixedData8(append(maxNID, []byte("leaf_1")...)),
namespace.PrefixedData8(append(maxNID, []byte("leaf_2")...)),
[]prefixedData8{
prefixedData8(append(maxNID, []byte("leaf_1")...)),
prefixedData8(append(maxNID, []byte("leaf_2")...)),
},
maxNID,
},
{
"two leaves with MaxNID (not ignored)",
false,
[]namespace.PrefixedData8{
namespace.PrefixedData8(append(maxNID, []byte("leaf_1")...)),
namespace.PrefixedData8(append(maxNID, []byte("leaf_2")...)),
[]prefixedData8{
prefixedData8(append(maxNID, []byte("leaf_1")...)),
prefixedData8(append(maxNID, []byte("leaf_2")...)),
},
maxNID,
},
{
"two leaves, none with MaxNID (ignored)",
true,
[]namespace.PrefixedData8{
namespace.PrefixedData8(append(minNID, []byte("leaf_1")...)),
namespace.PrefixedData8(append(secondNID, []byte("leaf_2")...)),
[]prefixedData8{
prefixedData8(append(minNID, []byte("leaf_1")...)),
prefixedData8(append(secondNID, []byte("leaf_2")...)),
},
secondNID,
},
{
"two leaves, none with MaxNID (not ignored)",
false,
[]namespace.PrefixedData8{
namespace.PrefixedData8(append(minNID, []byte("leaf_1")...)),
namespace.PrefixedData8(append(secondNID, []byte("leaf_2")...)),
[]prefixedData8{
prefixedData8(append(minNID, []byte("leaf_1")...)),
prefixedData8(append(secondNID, []byte("leaf_2")...)),
},
secondNID,
},
{
"three leaves, one with MaxNID (ignored)",
true,
[]namespace.PrefixedData8{
namespace.PrefixedData8(append(minNID, []byte("leaf_1")...)),
namespace.PrefixedData8(append(secondNID, []byte("leaf_2")...)),
namespace.PrefixedData8(append(maxNID, []byte("leaf_2")...)),
[]prefixedData8{
prefixedData8(append(minNID, []byte("leaf_1")...)),
prefixedData8(append(secondNID, []byte("leaf_2")...)),
prefixedData8(append(maxNID, []byte("leaf_2")...)),
},
secondNID,
},
{
"three leaves, one with MaxNID (not ignored)",
false,
[]namespace.PrefixedData8{
namespace.PrefixedData8(append(minNID, []byte("leaf_1")...)),
namespace.PrefixedData8(append(secondNID, []byte("leaf_2")...)),
namespace.PrefixedData8(append(maxNID, []byte("leaf_2")...)),
[]prefixedData8{
prefixedData8(append(minNID, []byte("leaf_1")...)),
prefixedData8(append(secondNID, []byte("leaf_2")...)),
prefixedData8(append(maxNID, []byte("leaf_2")...)),
},
maxNID,
},

{
"4 leaves, none maxNID (ignored)", true,
[]namespace.PrefixedData8{
namespace.PrefixedData8(append(minNID, []byte("leaf_1")...)),
namespace.PrefixedData8(append(minNID, []byte("leaf_2")...)),
namespace.PrefixedData8(append(secondNID, []byte("leaf_3")...)),
namespace.PrefixedData8(append(thirdNID, []byte("leaf_4")...)),
[]prefixedData8{
prefixedData8(append(minNID, []byte("leaf_1")...)),
prefixedData8(append(minNID, []byte("leaf_2")...)),
prefixedData8(append(secondNID, []byte("leaf_3")...)),
prefixedData8(append(thirdNID, []byte("leaf_4")...)),
},
thirdNID,
},
{
"4 leaves, half maxNID (ignored)",
true,
[]namespace.PrefixedData8{
namespace.PrefixedData8(append(minNID, []byte("leaf_1")...)),
namespace.PrefixedData8(append(secondNID, []byte("leaf_2")...)),
namespace.PrefixedData8(append(maxNID, []byte("leaf_3")...)),
namespace.PrefixedData8(append(maxNID, []byte("leaf_4")...)),
[]prefixedData8{
prefixedData8(append(minNID, []byte("leaf_1")...)),
prefixedData8(append(secondNID, []byte("leaf_2")...)),
prefixedData8(append(maxNID, []byte("leaf_3")...)),
prefixedData8(append(maxNID, []byte("leaf_4")...)),
},
secondNID,
},
{
"4 leaves, half maxNID (not ignored)",
false,
[]namespace.PrefixedData8{
namespace.PrefixedData8(append(minNID, []byte("leaf_1")...)),
namespace.PrefixedData8(append(secondNID, []byte("leaf_2")...)),
namespace.PrefixedData8(append(maxNID, []byte("leaf_3")...)),
namespace.PrefixedData8(append(maxNID, []byte("leaf_4")...)),
[]prefixedData8{
prefixedData8(append(minNID, []byte("leaf_1")...)),
prefixedData8(append(secondNID, []byte("leaf_2")...)),
prefixedData8(append(maxNID, []byte("leaf_3")...)),
prefixedData8(append(maxNID, []byte("leaf_4")...)),
},
maxNID,
},
{
"8 leaves, 4 maxNID (ignored)",
true,
[]namespace.PrefixedData8{
namespace.PrefixedData8(append(minNID, []byte("leaf_1")...)),
namespace.PrefixedData8(append(secondNID, []byte("leaf_2")...)),
namespace.PrefixedData8(append(thirdNID, []byte("leaf_3")...)),
namespace.PrefixedData8(append(thirdNID, []byte("leaf_4")...)),
namespace.PrefixedData8(append(maxNID, []byte("leaf_5")...)),
namespace.PrefixedData8(append(maxNID, []byte("leaf_6")...)),
namespace.PrefixedData8(append(maxNID, []byte("leaf_7")...)),
namespace.PrefixedData8(append(maxNID, []byte("leaf_8")...)),
[]prefixedData8{
prefixedData8(append(minNID, []byte("leaf_1")...)),
prefixedData8(append(secondNID, []byte("leaf_2")...)),
prefixedData8(append(thirdNID, []byte("leaf_3")...)),
prefixedData8(append(thirdNID, []byte("leaf_4")...)),
prefixedData8(append(maxNID, []byte("leaf_5")...)),
prefixedData8(append(maxNID, []byte("leaf_6")...)),
prefixedData8(append(maxNID, []byte("leaf_7")...)),
prefixedData8(append(maxNID, []byte("leaf_8")...)),
},
thirdNID,
},
Expand Down

0 comments on commit 708cacd

Please sign in to comment.