From 3807cc27a60c402ed5124ceb13d4b150c0bddd25 Mon Sep 17 00:00:00 2001 From: Chris O'Hara Date: Sat, 18 Nov 2023 13:03:17 +1000 Subject: [PATCH] Store the root object in a region --- types/serde.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/types/serde.go b/types/serde.go index af994a8..11e20c5 100644 --- a/types/serde.go +++ b/types/serde.go @@ -49,13 +49,19 @@ func Serialize(x any) ([]byte, error) { // Scan pointers to collect memory regions. s.scan(t, p) + rootType := reflect.TypeOf(wr.Elem().Interface()) + rootTypeID := s.types.ToType(rootType) + serializeAny(s, t, p) state := &coroutinev1.State{ - State: s.b, Build: buildInfo, Types: s.types.types, Functions: s.funcs.funcs, + Root: &coroutinev1.Region{ + Type: int32(rootTypeID), + Data: s.b, + }, } return state.MarshalVT() } @@ -70,12 +76,14 @@ func Deserialize(b []byte) (interface{}, error) { return nil, fmt.Errorf("%w: got %v, expect %v", ErrBuildIDMismatch, state.Build.Id, buildInfo.Id) } - d := newDeserializer(state.State, state.Types, state.Functions) + d := newDeserializer(state.Root.Data, state.Types, state.Functions) + var x interface{} px := &x t := reflect.TypeOf(px).Elem() p := unsafe.Pointer(px) deserializeInterface(d, t, p) + if len(d.b) != 0 { return nil, errors.New("trailing bytes") }