aboutsummaryrefslogtreecommitdiffstats
path: root/rlp/encode.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-02-13 23:08:30 +0800
committerobscuren <geffobscura@gmail.com>2015-02-13 23:08:30 +0800
commit5c251b69282b3992512d0c17ed0063f294a0e663 (patch)
tree7842c1a6ac8394e8bebfd4f27c9222b497aaf0f6 /rlp/encode.go
parent75d164037fb9bbf75def7c5501727fd634ef124f (diff)
parentbde3ff16ad98cb4ab0befc899f7f0584d21ff9a4 (diff)
downloaddexon-5c251b69282b3992512d0c17ed0063f294a0e663.tar
dexon-5c251b69282b3992512d0c17ed0063f294a0e663.tar.gz
dexon-5c251b69282b3992512d0c17ed0063f294a0e663.tar.bz2
dexon-5c251b69282b3992512d0c17ed0063f294a0e663.tar.lz
dexon-5c251b69282b3992512d0c17ed0063f294a0e663.tar.xz
dexon-5c251b69282b3992512d0c17ed0063f294a0e663.tar.zst
dexon-5c251b69282b3992512d0c17ed0063f294a0e663.zip
Merge branch 'fjl-poc8-net-integration' into develop
Diffstat (limited to 'rlp/encode.go')
-rw-r--r--rlp/encode.go22
1 files changed, 21 insertions, 1 deletions
diff --git a/rlp/encode.go b/rlp/encode.go
index 6ae4a123a..9d11d66bf 100644
--- a/rlp/encode.go
+++ b/rlp/encode.go
@@ -350,8 +350,10 @@ func makeWriter(typ reflect.Type) (writer, error) {
return writeUint, nil
case kind == reflect.String:
return writeString, nil
- case kind == reflect.Slice && typ.Elem().Kind() == reflect.Uint8 && !typ.Elem().Implements(encoderInterface):
+ case kind == reflect.Slice && isByte(typ.Elem()):
return writeBytes, nil
+ case kind == reflect.Array && isByte(typ.Elem()):
+ return writeByteArray, nil
case kind == reflect.Slice || kind == reflect.Array:
return makeSliceWriter(typ)
case kind == reflect.Struct:
@@ -363,6 +365,10 @@ func makeWriter(typ reflect.Type) (writer, error) {
}
}
+func isByte(typ reflect.Type) bool {
+ return typ.Kind() == reflect.Uint8 && !typ.Implements(encoderInterface)
+}
+
func writeUint(val reflect.Value, w *encbuf) error {
i := val.Uint()
if i == 0 {
@@ -407,6 +413,20 @@ func writeBytes(val reflect.Value, w *encbuf) error {
return nil
}
+func writeByteArray(val reflect.Value, w *encbuf) error {
+ if !val.CanAddr() {
+ // Slice requires the value to be addressable.
+ // Make it addressable by copying.
+ copy := reflect.New(val.Type()).Elem()
+ copy.Set(val)
+ val = copy
+ }
+ size := val.Len()
+ slice := val.Slice(0, size).Bytes()
+ w.encodeString(slice)
+ return nil
+}
+
func writeString(val reflect.Value, w *encbuf) error {
s := val.String()
w.encodeStringHeader(len(s))