diff options
author | Felix Lange <fjl@twurst.com> | 2014-12-09 17:41:47 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2014-12-09 17:58:46 +0800 |
commit | 93e858f88ef9a9a572c2dabd4aef8bbbd678dd97 (patch) | |
tree | 03136e2dcfaae7bedc1c39928d3e891a128f9159 /rlp/decode.go | |
parent | 4f12f0697e645a567fac9f13ed8cdb25e1218b84 (diff) | |
download | go-tangerine-93e858f88ef9a9a572c2dabd4aef8bbbd678dd97.tar go-tangerine-93e858f88ef9a9a572c2dabd4aef8bbbd678dd97.tar.gz go-tangerine-93e858f88ef9a9a572c2dabd4aef8bbbd678dd97.tar.bz2 go-tangerine-93e858f88ef9a9a572c2dabd4aef8bbbd678dd97.tar.lz go-tangerine-93e858f88ef9a9a572c2dabd4aef8bbbd678dd97.tar.xz go-tangerine-93e858f88ef9a9a572c2dabd4aef8bbbd678dd97.tar.zst go-tangerine-93e858f88ef9a9a572c2dabd4aef8bbbd678dd97.zip |
rlp: remove support for signed integer types
There is no agreement on how to encode negative integers
across implementations. cpp-ethereum doesn't support them either.
Diffstat (limited to 'rlp/decode.go')
-rw-r--r-- | rlp/decode.go | 35 |
1 files changed, 6 insertions, 29 deletions
diff --git a/rlp/decode.go b/rlp/decode.go index 7acbbfa0d..31485ee70 100644 --- a/rlp/decode.go +++ b/rlp/decode.go @@ -54,7 +54,7 @@ type Decoder interface { // To decode into a Go string, the input must be an RLP string. The // bytes are taken as-is and will not necessarily be valid UTF-8. // -// To decode into an integer type, the input must also be an RLP +// To decode into an unsigned integer type, the input must also be an RLP // string. The bytes are interpreted as a big endian representation of // the integer. If the RLP string is larger than the bit size of the // type, Decode will return an error. Decode also supports *big.Int. @@ -66,8 +66,9 @@ type Decoder interface { // []interface{}, for RLP lists // []byte, for RLP strings // -// Non-empty interface types are not supported, nor are bool, float32, -// float64, maps, channel types and functions. +// Non-empty interface types are not supported, nor are booleans, +// signed integers, floating point numbers, maps, channels and +// functions. func Decode(r io.Reader, val interface{}) error { return NewStream(r).Decode(val) } @@ -97,8 +98,8 @@ func makeDecoder(typ reflect.Type) (dec decoder, err error) { return decodeBigInt, nil case typ.AssignableTo(bigInt): return decodeBigIntNoPtr, nil - case isInteger(kind): - return makeNumDecoder(typ), nil + case isUint(kind): + return decodeUint, nil case kind == reflect.String: return decodeString, nil case kind == reflect.Slice || kind == reflect.Array: @@ -114,30 +115,6 @@ func makeDecoder(typ reflect.Type) (dec decoder, err error) { } } -func makeNumDecoder(typ reflect.Type) decoder { - kind := typ.Kind() - switch { - case kind <= reflect.Int64: - return decodeInt - case kind <= reflect.Uint64: - return decodeUint - default: - panic("fallthrough") - } -} - -func decodeInt(s *Stream, val reflect.Value) error { - typ := val.Type() - num, err := s.uint(typ.Bits()) - if err == errUintOverflow { - return decodeError{"input string too long", typ} - } else if err != nil { - return err - } - val.SetInt(int64(num)) - return nil -} - func decodeUint(s *Stream, val reflect.Value) error { typ := val.Type() num, err := s.uint(typ.Bits()) |