Skip to content

Commit

Permalink
Need to store type URL alongside serialized proto.Message
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Jun 17, 2024
1 parent 8c2c65c commit e593364
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions serde.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/dispatchrun/coroutine/types"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
)

func init() {
Expand All @@ -21,12 +22,19 @@ func protoSerializer(s *types.Serializer, mp *proto.Message) error {
types.SerializeT(s, false)
return nil
}
b, err := proto.Marshal(m)

any, err := anypb.New(m)
if err != nil {
return fmt.Errorf("anypb.New: %w", err)
}
b, err := proto.Marshal(any)
if err != nil {
return fmt.Errorf("proto.Marshal: %w", err)
}

types.SerializeT(s, true)
types.SerializeT(s, b)

return nil
}

Expand All @@ -41,10 +49,14 @@ func protoDeserializer(d *types.Deserializer, mp *proto.Message) error {
var b []byte
types.DeserializeTo(d, &b)

var m proto.Message
if err := proto.Unmarshal(b, m); err != nil {
var any anypb.Any
if err := proto.Unmarshal(b, &any); err != nil {
return fmt.Errorf("proto.Unmarshal: %w", err)
}
m, err := any.UnmarshalNew()
if err != nil {
return fmt.Errorf("anypb.UnmarshalNew: %w", err)
}
*mp = m

return nil
Expand Down

0 comments on commit e593364

Please sign in to comment.