diff options
author | Felix Lange <fjl@twurst.com> | 2015-12-22 04:05:20 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-02-19 18:14:29 +0800 |
commit | bb07ce3eedabb2133227ba1d7569d171d8e5b25c (patch) | |
tree | 9e5b8ff9506f39ca1b94a21833b96646ccb7a19b /rlp/encode.go | |
parent | fdb936ee95d09b1b98418735a813deba6770ad5a (diff) | |
download | dexon-bb07ce3eedabb2133227ba1d7569d171d8e5b25c.tar dexon-bb07ce3eedabb2133227ba1d7569d171d8e5b25c.tar.gz dexon-bb07ce3eedabb2133227ba1d7569d171d8e5b25c.tar.bz2 dexon-bb07ce3eedabb2133227ba1d7569d171d8e5b25c.tar.lz dexon-bb07ce3eedabb2133227ba1d7569d171d8e5b25c.tar.xz dexon-bb07ce3eedabb2133227ba1d7569d171d8e5b25c.tar.zst dexon-bb07ce3eedabb2133227ba1d7569d171d8e5b25c.zip |
rlp: add "tail" struct tag
Diffstat (limited to 'rlp/encode.go')
-rw-r--r-- | rlp/encode.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/rlp/encode.go b/rlp/encode.go index d73b17c28..17cfc6b66 100644 --- a/rlp/encode.go +++ b/rlp/encode.go @@ -345,7 +345,7 @@ var ( ) // makeWriter creates a writer function for the given type. -func makeWriter(typ reflect.Type) (writer, error) { +func makeWriter(typ reflect.Type, ts tags) (writer, error) { kind := typ.Kind() switch { case typ == rawValueType: @@ -371,7 +371,7 @@ func makeWriter(typ reflect.Type) (writer, error) { case kind == reflect.Array && isByte(typ.Elem()): return writeByteArray, nil case kind == reflect.Slice || kind == reflect.Array: - return makeSliceWriter(typ) + return makeSliceWriter(typ, ts) case kind == reflect.Struct: return makeStructWriter(typ) case kind == reflect.Ptr: @@ -507,20 +507,21 @@ func writeInterface(val reflect.Value, w *encbuf) error { return ti.writer(eval, w) } -func makeSliceWriter(typ reflect.Type) (writer, error) { +func makeSliceWriter(typ reflect.Type, ts tags) (writer, error) { etypeinfo, err := cachedTypeInfo1(typ.Elem(), tags{}) if err != nil { return nil, err } writer := func(val reflect.Value, w *encbuf) error { - lh := w.list() + if !ts.tail { + defer w.listEnd(w.list()) + } vlen := val.Len() for i := 0; i < vlen; i++ { if err := etypeinfo.writer(val.Index(i), w); err != nil { return err } } - w.listEnd(lh) return nil } return writer, nil |