From 34d62c380ef6327c170639af6221a82610efa25c Mon Sep 17 00:00:00 2001
From: obscuren <obscuren@obscura.com>
Date: Wed, 1 Jan 2014 03:06:52 +0100
Subject: [PATCH] Encoding helpers for trie

---
 encoding.go      | 16 ++++++++++++++++
 encoding_test.go | 12 ------------
 2 files changed, 16 insertions(+), 12 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)
diff --git a/encoding_test.go b/encoding_test.go
index 63f7878bf..b66f702ac 100644
--- a/encoding_test.go
+++ b/encoding_test.go
@@ -27,18 +27,6 @@ func TestCompactEncode(t *testing.T) {
   }
 }
 
-// Helper function for comparing slices
-func CompareIntSlice(a, b []int) bool {
-  if len(a) != len(b) {
-    return false
-  }
-  for i, v := range a {
-    if v != b[i] {
-      return false
-    }
-  }
-  return true
-}
 
 func TestCompactHexDecode(t *testing.T) {
   exp := []int{7, 6, 6, 5, 7, 2, 6, 2, 16}
-- 
GitLab