-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
101 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package namespace | ||
|
||
type PrefixedData struct { | ||
namespaceLen int | ||
prefixedData []byte | ||
} | ||
|
||
func (n PrefixedData) NamespaceID() ID { | ||
return n.prefixedData[:n.namespaceLen] | ||
} | ||
|
||
func (n PrefixedData) Data() []byte { | ||
return n.prefixedData[n.namespaceLen:] | ||
} | ||
|
||
func (n PrefixedData) Bytes() []byte { | ||
return n.prefixedData | ||
} | ||
|
||
func (n PrefixedData) NamespaceSize() int { | ||
return n.namespaceLen | ||
} | ||
|
||
func NewPrefixedData(namespaceLen int, prefixedData []byte) *PrefixedData { | ||
return &PrefixedData{ | ||
namespaceLen: namespaceLen, | ||
prefixedData: prefixedData, | ||
} | ||
} | ||
|
||
func PrefixedDataFrom(namespace []byte, data []byte) *PrefixedData { | ||
return &PrefixedData{ | ||
namespaceLen: len(namespace), | ||
prefixedData: append(namespace, data...), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package namespace | ||
|
||
import "bytes" | ||
|
||
type ID []byte | ||
|
||
func (nid ID) Less(other ID) bool { | ||
return bytes.Compare(nid, other) < 0 | ||
} | ||
|
||
func (nid ID) Equal(other ID) bool { | ||
return bytes.Equal(nid, other) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package nmt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.