Skip to content

Commit

Permalink
rlp: add functions for encoding
Browse files Browse the repository at this point in the history
I'm reasonably confident that the encoding matches the output of
ethutil.Encode for values that it supports. Some of the tests have been
adpated from the Ethereum testing repository.

There are still TODOs in the code.
  • Loading branch information
fjl committed Jan 15, 2015
1 parent bb55307 commit 552f5b2
Show file tree
Hide file tree
Showing 6 changed files with 860 additions and 17 deletions.
12 changes: 3 additions & 9 deletions rlp/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,9 @@ type field struct {
}

func makeStructDecoder(typ reflect.Type) (decoder, error) {
var fields []field
for i := 0; i < typ.NumField(); i++ {
if f := typ.Field(i); f.PkgPath == "" { // exported
info, err := cachedTypeInfo1(f.Type)
if err != nil {
return nil, err
}
fields = append(fields, field{i, info})
}
fields, err := structFields(typ)
if err != nil {
return nil, err
}
dec := func(s *Stream, val reflect.Value) (err error) {
if _, err = s.List(); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions rlp/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ func ExampleStream() {
}

func BenchmarkDecode(b *testing.B) {
enc := encTest(90000)
enc := encodeTestSlice(90000)
b.SetBytes(int64(len(enc)))
b.ReportAllocs()
b.ResetTimer()
Expand All @@ -524,7 +524,7 @@ func BenchmarkDecode(b *testing.B) {
}

func BenchmarkDecodeIntSliceReuse(b *testing.B) {
enc := encTest(100000)
enc := encodeTestSlice(100000)
b.SetBytes(int64(len(enc)))
b.ReportAllocs()
b.ResetTimer()
Expand All @@ -538,7 +538,7 @@ func BenchmarkDecodeIntSliceReuse(b *testing.B) {
}
}

func encTest(n int) []byte {
func encodeTestSlice(n int) []byte {
s := make([]interface{}, n)
for i := 0; i < n; i++ {
s[i] = i
Expand Down
Loading

0 comments on commit 552f5b2

Please sign in to comment.