I’d like to configure scalaPB
to automatically convert actorRefs
to and from their serialized string format.
This can be done in theory using scalaPB TypeMapper
s, and such a type mapper could looks as simple as this:
TypeMapper[String, ActorRef](system.provider.resolveActorRef)(Serialization.serializedActorPath)
I.e. we instruct scalaPB to serialize from actorRef to string using Serialization.serializedActorPath
, and from string to actorRef using system.provider.resolveActorRef
.
Then you could use it like this in a protobuf message:
string recipient = 1 [(scalapb.field).type = "akka.actor.ActorRef"];
Now, the problem is that system
is of course not available to ScalaPB at that time in the TypeMapper
. At least not the way it’s done above.
Is there any other way how I can automatize the serialization/deserialization of actorRefs, so that I don’t have to add an extra wrapper class for each actorRef in messages? A way how I can make the actorSystem available “at compile time”? Maybe a suggestion involving dependency injection frameworks? Or a solution based on Akka serialization adapters?
PS: With implicit conversion (implicit unwrapping) I get half way, i.e. by having an implicit converter that takes an implicit ActorSystem
, and implicitly returns ActorRef
. Only wrappedRef ! message
does not work, because the tell
also has an implicit sender
argument, which becomes just too many implicits for the compiler to handle.