@ignatius wrote:
I’d like to configure
scalaPB
to automatically convertactorRefs
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 usingsystem.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 theTypeMapper
. 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 returnsActorRef
. OnlywrappedRef ! message
does not work, because thetell
also has an implicitsender
argument, which becomes just too many implicits for the compiler to handle.
Posts: 4
Participants: 2