Age, Martin, Johannes, thanks for the responses and explanations – and sorry for the late reply, I have only just gotten back to this.
In the meantime, I have written the marshalling code to handle content negation, and have posted it
in the thread that Age mentioned. The missing bits for the Protobuff-specific marshalling are these:
object ProtobufProtocols {
val ProtobufMediaType = MediaTypes.register(MediaType.custom("application", "protobuf", compressible = false, binary = true))
val Protobuf = ContentType(ProtobufMediaType)
implicit def marshaller[T <: com.google.protobuf.MessageLite]() =
Marshaller.of[T](Protobuf) {
(value, contentType, ctx) ⇒
ctx.marshalTo(HttpEntity(contentType, value.toByteArray))
}
implicit def unmarshaller[T <: net.sandrogrzicic.scalabuff.Message]() =
Unmarshaller[T](ProtobufMediaType) {
case HttpBody(contentType, buffer) =>
// TODO
}
}
However, I have run into a bit of a problem when trying to write some generic unmarshalling code: for each Protobuf message M that you compile to a Scala case class using
ScalaBuff, there are three ways to deserialize from a buffer: either you call the method parseFrom(buffer) on M's object, you create a new instance m of M (without constructor arguments) and call m.parseFrom(buffer), or you use the defaultInstance in M's object and call parseFrom(buffer) on it.
Does anybody know how to achieve this within an Unmarshaller?
Any help most welcome!
Cheers,
Kaspar