aboutsummaryrefslogtreecommitdiffstats
path: root/rlp.go
diff options
context:
space:
mode:
authorobscuren <obscuren@obscura.com>2013-12-28 22:17:26 +0800
committerobscuren <obscuren@obscura.com>2013-12-28 22:17:26 +0800
commit95d877f701371108dc18967319d1f7b4e6763caf (patch)
tree31e00c66a27d57600624e84cc230d6bae047cce0 /rlp.go
parentbb8afba20a56552cef71681f72fb192bcda88c1d (diff)
downloadgo-tangerine-95d877f701371108dc18967319d1f7b4e6763caf.tar
go-tangerine-95d877f701371108dc18967319d1f7b4e6763caf.tar.gz
go-tangerine-95d877f701371108dc18967319d1f7b4e6763caf.tar.bz2
go-tangerine-95d877f701371108dc18967319d1f7b4e6763caf.tar.lz
go-tangerine-95d877f701371108dc18967319d1f7b4e6763caf.tar.xz
go-tangerine-95d877f701371108dc18967319d1f7b4e6763caf.tar.zst
go-tangerine-95d877f701371108dc18967319d1f7b4e6763caf.zip
Fixed rlp encoding
Diffstat (limited to 'rlp.go')
-rw-r--r--rlp.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/rlp.go b/rlp.go
index 2c04317ae..bc3b6a151 100644
--- a/rlp.go
+++ b/rlp.go
@@ -41,25 +41,34 @@ func FromBin(data []byte) uint64 {
}
func Decode(data []byte, pos int) (interface{}, int) {
+ if pos > len(data)-1 {
+ panic(fmt.Sprintf("index out of range %d for data %q, l = %d", pos, data, len(data)))
+ }
+
char := int(data[pos])
slice := make([]interface{}, 0)
switch {
case char < 24:
return data[pos], pos + 1
+
case char < 56:
b := int(data[pos]) - 23
return FromBin(data[pos+1 : pos+1+b]), pos + 1 + b
+
case char < 64:
b := int(data[pos]) - 55
b2 := int(FromBin(data[pos+1 : pos+1+b]))
return FromBin(data[pos+1+b : pos+1+b+b2]), pos+1+b+b2
+
case char < 120:
b := int(data[pos]) - 64
return data[pos+1:pos+1+b], pos+1+b
+
case char < 128:
b := int(data[pos]) - 119
b2 := int(FromBin(data[pos+1 : pos+1+b]))
return data[pos+1+b : pos+1+b+b2], pos+1+b+b2
+
case char < 184:
b := int(data[pos]) - 128
pos++
@@ -70,6 +79,7 @@ func Decode(data []byte, pos int) (interface{}, int) {
slice = append(slice, obj)
}
return slice, pos
+
case char < 192:
b := int(data[pos]) - 183
//b2 := int(FromBin(data[pos+1 : pos+1+b])) (ref implementation has an unused variable)
@@ -122,7 +132,7 @@ func Encode(object interface{}) []byte {
case []byte:
// Cast the byte slice to a string
- buff.Write(Encode(string(t)))
+ //buff.Write(Encode(string(t)))
case []interface{}, []string:
// Inline function for writing the slice header