Play lets you return a number of different types directly in your controllers, such as JsValue or XML along with plain text. I would like to extend this to accept protocol buffers, so I can write:
def page = Action {
val protobuf = //...
Ok(protobuf)
}
Protocol buffers in Java all inherit from a single
com.google.protobuf.Messageclass.Add the following implicit conversions within the scope of your application controller:
These will allow Play to serialize buffers directly in a response given by a status such as
Ok(protobuf)Update:
I have posted a working example of the reverse situation, where the incoming request can be parsed and a protobuf can be extracted automatically.
The parser takes the form of an action in this example, tho you could also code a body parser:
The client sending the request should serialize the buffer as a byte array, and pass it directly in the body of the request.