I'm using ScalaPB for my protobuf compiler which generates Scala case classes, parsers and serializers for my protocol buffers.
I have a simple protobuf message in a .proto file that has been compiled to a Scala case class thanks to ScalaPB.
option java_outer_classname = "MovementProtos";
message Move {
required string direction = 1;
required string mode = 2;
}
This file is compiled and allows me to do something like:
val move = Move(direction = "up", mode = "walk")
I have an Akka actor handling a TCP connection.
class PacketHandler extends Actor {
def receive: Receive = {
case m: Move =>
// successfully matched against Move case class message
case Tcp.Received(data) =>
// didn't match any messages
case _: Tcp.ConnectionClosed =>
context.stop(self)
}
}
If I send a Move
protobuf message to my PacketHandler
, will it successfully match against my Move
case class with how I've wrote my receive
?
How do I send a Move
protobuf message? Let's say when it successfully matches against a Move
protobuf message it echoes it back.
def receive: Receive = {
case m: Move =>
// successfully matched against Move case class message
// now echo back 'm' over the wire
sender ! Tcp.Write(???)
...
}
I have no client to test my PacketHandler
actor so I've been using telnet.
It would also be useful to know what the encoded Move
message looks like exactly so I can create my connection over telnet and send the encoded message over the wire and test whether it gets decoded when it reaches PacketHandler
.