Ok so after playing around I found a solution where I pass the proto marshaller/unmarshaller manually.
For example, when sending a request:
Marshal(ApiCall())
.to[RequestEntity](PredefinedToEntityMarshallers.ByteArrayMarshaller.compose[ApiCall](r => r.toByteArray))
.map({ entity =>
})
And when receiving a response:
Unmarshal(entity)
.to[ApiResponse](Unmarshaller.byteArrayUnmarshaller.map[ApiResponse](bytes => ApiResponse.parseFrom(bytes)))
.map { apiResponse =>
}
But what I'm confused about is how in my ServerRoute
class, I just use with ProtobufMarshalling[ApiCall, ApiResponse]
and scala picks up on the marshallers inside the trait. Here, I have had to explicitly pass the marshalling function inside to[<type>](<marshaller/unmarshaller>)
.
Could someone explain this please?