Skip to content

Commit

Permalink
Simplify the scanner so that it accepts a reflect.Value
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Jul 5, 2024
1 parent 20d7a74 commit 98b6ab4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
4 changes: 1 addition & 3 deletions types/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,7 @@ func (c *containers) insert(x container) int {
return i
}

func (s *Serializer) scan(t reflect.Type, p unsafe.Pointer) {
v := reflect.NewAt(t, p).Elem()

func (s *Serializer) scan(v reflect.Value) {
sc := &scanner{
seen: map[reflect.Value]struct{}{},
containers: &s.containers,
Expand Down
10 changes: 4 additions & 6 deletions types/serde.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,12 @@ func init() {
func Serialize(x any) ([]byte, error) {
s := newSerializer()

i := &x // w is *interface{}
vp := reflect.ValueOf(i)
t := vp.Elem().Type() // what x contains
v := reflect.ValueOf(&x).Elem()

// Scan pointers to collect memory regions.
s.scan(t, vp.UnsafePointer())
s.scan(v)

s.Serialize(vp.Elem())
s.Serialize(v)

state := &coroutinev1.State{
Build: buildInfo,
Expand All @@ -58,7 +56,7 @@ func Serialize(x any) ([]byte, error) {
Strings: s.strings.strings,
Regions: s.regions,
Root: &coroutinev1.Region{
Type: s.types.ToType(t) << 1,
Type: s.types.ToType(v.Type()) << 1,
Data: s.buffer,
},
}
Expand Down

0 comments on commit 98b6ab4

Please sign in to comment.