From ef422ee1e1eef831c681aaec31ce7da23b12ae6d Mon Sep 17 00:00:00 2001 From: zsfelfoldi Date: Mon, 30 Nov 2015 13:34:19 +0100 Subject: light: implemented odr-capable trie and state structures --- trie/encoding.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'trie/encoding.go') diff --git a/trie/encoding.go b/trie/encoding.go index 3c172b843..761bad188 100644 --- a/trie/encoding.go +++ b/trie/encoding.go @@ -69,6 +69,27 @@ func compactHexDecode(str []byte) []byte { return nibbles } +// compactHexEncode encodes a series of nibbles into a byte array +func compactHexEncode(nibbles []byte) []byte { + nl := len(nibbles) + if nl == 0 { + return nil + } + if nibbles[nl-1] == 16 { + nl-- + } + l := (nl + 1) / 2 + var str = make([]byte, l) + for i, _ := range str { + b := nibbles[i*2] * 16 + if nl > i*2 { + b += nibbles[i*2+1] + } + str[i] = b + } + return str +} + func decodeCompact(key []byte) []byte { l := len(key) / 2 var res = make([]byte, l) -- cgit