aboutsummaryrefslogtreecommitdiffstats
path: root/encoding.go
diff options
context:
space:
mode:
authorobscuren <obscuren@obscura.com>2014-01-01 10:06:52 +0800
committerobscuren <obscuren@obscura.com>2014-01-01 10:06:52 +0800
commit34d62c380ef6327c170639af6221a82610efa25c (patch)
tree3c519214bb48628a3b68fa49d18f5b5c9def4f8e /encoding.go
parent276fa6c799b08bc41efd2d26a83eef678e8c943b (diff)
downloadgo-tangerine-34d62c380ef6327c170639af6221a82610efa25c.tar
go-tangerine-34d62c380ef6327c170639af6221a82610efa25c.tar.gz
go-tangerine-34d62c380ef6327c170639af6221a82610efa25c.tar.bz2
go-tangerine-34d62c380ef6327c170639af6221a82610efa25c.tar.lz
go-tangerine-34d62c380ef6327c170639af6221a82610efa25c.tar.xz
go-tangerine-34d62c380ef6327c170639af6221a82610efa25c.tar.zst
go-tangerine-34d62c380ef6327c170639af6221a82610efa25c.zip
Encoding helpers for trie
Diffstat (limited to 'encoding.go')
-rw-r--r--encoding.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/encoding.go b/encoding.go
index ca30b47c9..d77303817 100644
--- a/encoding.go
+++ b/encoding.go
@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/hex"
"strings"
+ _"fmt"
)
func CompactEncode(hexSlice []int) string {
@@ -32,6 +33,21 @@ func CompactEncode(hexSlice []int) string {
return buff.String()
}
+func CompactDecode(str string) []int {
+ base := CompactHexDecode(str)
+ base = base[:len(base)-1]
+ if base[0] >= 2 {// && base[len(base)-1] != 16 {
+ base = append(base, 16)
+ }
+ if base[0] % 2 == 1 {
+ base = base[1:]
+ } else {
+ base = base[2:]
+ }
+
+ return base
+}
+
func CompactHexDecode(str string) []int {
base := "0123456789abcdef"
hexSlice := make([]int, 0)