79361331

Date: 2025-01-16 11:10:04
Score: 4.5
Natty:
Report link

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?

Reasons:
  • RegEx Blacklisted phrase (2.5): Could someone explain
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Kris Rice