Any argument that implements the `proto.message` as argument

78 views
Skip to first unread message

Ricardo Ambrogi

unread,
Mar 6, 2023, 11:41:21 AM3/6/23
to Service Weaver
I'm trying to create a method, that accepts any serializable argument as a value. Although this doesn't seem to work:

```
// T is the interface that the MeiliSearch service implements.
type T interface {
Search(ctx context.Context, query string) ([]*clubv1.Club, error)
Index(ctx context.Context, index string, document *proto.Message) error
}
```

error:
```
meilisearchservice/service.go:23:2: Method `Index(ctx context.Context, index string, document *protoreflect.ProtoMessage) (error)` of Service Weaver component "T" has incorrect argument types. Argument 2 has type *protoreflect.ProtoMessage, which is not serializable. All arguments, besides the initial context.Context, must be serializable.
```


Any ideas on how can I achieve the desired result?

mwhittaker

unread,
Mar 6, 2023, 12:16:32 PM3/6/23
to Service Weaver
Hi Ricardo, 

I think the problem is that proto.Message is an interface, and interfaces are currently not serializable. If you have a specific proto in mind, say Foo, you can try replacing *proto.Message with *Foo. If that doesn't work, you can also try playing around with using a []byte instead of a *proto.Message, or you could replace *proto.Message with a custom type that implements the encoding.BinaryMarshaler and encoding.BinaryUnmarshaler interfaces. 

Hopefully that solves your problem, but if not, please reach out again and we can try to help!

Best,
Michael

Reply all
Reply to author
Forward
0 new messages