aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil/rlp.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-08-01 16:21:43 +0800
committerobscuren <geffobscura@gmail.com>2014-08-01 16:21:43 +0800
commit5ede1224e48fd82961bd4a0b2ec1a3eda0b6d99b (patch)
treee973b3c2632d2d2a22d9c2949340f179faae152d /ethutil/rlp.go
parent5a2d62e4d9e551f16f094216da70b7a6f5d2bf00 (diff)
downloaddexon-5ede1224e48fd82961bd4a0b2ec1a3eda0b6d99b.tar.gz
dexon-5ede1224e48fd82961bd4a0b2ec1a3eda0b6d99b.tar.zst
dexon-5ede1224e48fd82961bd4a0b2ec1a3eda0b6d99b.zip
minor rlp things
Diffstat (limited to 'ethutil/rlp.go')
-rw-r--r--ethutil/rlp.go21
1 files changed, 8 insertions, 13 deletions
diff --git a/ethutil/rlp.go b/ethutil/rlp.go
index 333a84927..cf7f97ffd 100644
--- a/ethutil/rlp.go
+++ b/ethutil/rlp.go
@@ -32,12 +32,14 @@ const (
RlpEmptyStr = 0x40
)
+const rlpEof = -1
+
func Char(c []byte) int {
if len(c) > 0 {
return int(c[0])
}
- return 0
+ return rlpEof
}
func DecodeWithReader(reader *bytes.Buffer) interface{} {
@@ -46,8 +48,6 @@ func DecodeWithReader(reader *bytes.Buffer) interface{} {
// Read the next byte
char := Char(reader.Next(1))
switch {
- case char == 0:
- return nil
case char <= 0x7f:
return char
@@ -63,11 +63,7 @@ func DecodeWithReader(reader *bytes.Buffer) interface{} {
length := int(char - 0xc0)
for i := 0; i < length; i++ {
obj := DecodeWithReader(reader)
- if obj != nil {
- slice = append(slice, obj)
- } else {
- break
- }
+ slice = append(slice, obj)
}
return slice
@@ -75,13 +71,12 @@ func DecodeWithReader(reader *bytes.Buffer) interface{} {
length := ReadVarInt(reader.Next(int(char - 0xf7)))
for i := uint64(0); i < length; i++ {
obj := DecodeWithReader(reader)
- if obj != nil {
- slice = append(slice, obj)
- } else {
- break
- }
+ slice = append(slice, obj)
}
+
+ return slice
default:
+ panic(fmt.Sprintf("byte not supported: %q", char))
}
return slice