File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -131,18 +131,19 @@ func scanType(t reflect.Type) (Codec, error) {
131131
132132 case reflect .Struct :
133133 s := scanStruct (t )
134- v := make (reflectStructCodec , len (s .fields ))
134+ v := make (reflectStructCodec , 0 , len (s .fields ))
135135 for _ , i := range s .fields {
136136 field := t .Field (i )
137137 codec , err := scanType (field .Type )
138138 if err != nil {
139139 return nil , err
140140 }
141141
142- v [i ] = fieldCodec {
142+ // Append since unexported fields are skipped
143+ v = append (v , fieldCodec {
143144 Index : i ,
144145 Codec : codec ,
145- }
146+ })
146147 }
147148
148149 return & v , nil
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package binary
66import (
77 "bytes"
88 "reflect"
9+ "sync"
910 "testing"
1011
1112 "github.com/stretchr/testify/assert"
@@ -28,8 +29,6 @@ func TestScanner(t *testing.T) {
2829 e := NewEncoder (& b )
2930 err = codec .EncodeTo (e , reflect .Indirect (reflect .ValueOf (s0v )))
3031 assert .NoError (t , err )
31-
32- //e.Flush()
3332 assert .Equal (t , s0b , b .Bytes ())
3433}
3534
@@ -40,3 +39,22 @@ func TestScanner_Custom(t *testing.T) {
4039 assert .NoError (t , err )
4140 assert .NotNil (t , codec )
4241}
42+
43+ func TestScannerComposed (t * testing.T ) {
44+ codec , err := scan (reflect .TypeOf (Partition {}))
45+ assert .NoError (t , err )
46+ assert .NotNil (t , codec )
47+ }
48+
49+ type Partition struct {
50+ Strings
51+ Filters map [uint32 ][]uint64
52+ }
53+
54+ type Strings struct {
55+ lock sync.Mutex `binary:"-"`
56+ Key string
57+ Fill []uint64
58+ Hash []uint32
59+ Data map [uint64 ][]byte
60+ }
You can’t perform that action at this time.
0 commit comments