1

我使用 akka-mist 和 protobuf。语言斯卡拉。Protobuf 错误

测试发件人:

val (post, writer) = RestPostMock(ProtoBufPack.toByteString)
actor ? post

RestPostMock:

object RestPostMock extends Mockito {
  def apply(msg: ByteString): (Post, StringWriter) = {
    val httpRequest = mock[HttpServletRequest]
    httpRequest.getReader returns new BufferedReader(new StringReader(msg.toStringUtf8))
    ...

演员:

class CarStatusActor extends Actor {
  def receive = {
    case post: Post =>
      EventHandler.info(this, "received post test>>>>>>>>>>>>>>>>>>>")
      val readerInput = new ReaderInputStream(post.request.getReader)
      val protoBufPack = ProtoBufPack.parseFrom(readerInput)
      post.OK("Ok")
  }

结果:

INFO  [akka:event-driven:dispatcher:event:handler-1] akka.event.slf4j.Slf4jEventHandler - 
    [actorhandler.CarStatusActor]
    [received post test>>>>>>>>>>>>>>>>>>>]
ERROR [akka:event-driven:dispatcher:event:handler-1] akka.event.slf4j.Slf4jEventHandler - 
    [akka.testkit.TestActorRef]
    [Mock for Post, hashCode: 1039701893]
    [com.google.protobuf.InvalidProtocolBufferException: CodedInputStream encountered a malformed varint.
    at com.google.protobuf.InvalidProtocolBufferException.malformedVarint(InvalidProtocolBufferException.java:63)
4

0 回答 0