I can't parse protocol buffer sent through RabbitMQ

Viewed 915

I'm building a web service that sends and receives messages from RabbitMQ, it can send and the other side can read and make the parse. But the web service can't make the parse of the response. I'm using protoc 3.12.3, and Java Play Framework in the web service, the service that consumes the messages is going to be written in C++, but I have two mocks(Java and Python) that do the same and give the same error, I don't know what to do.

Here is the message:

syntax = "proto3";

option optimize_for = LITE_RUNTIME;

import "Subject.proto";

message FacialVerificationRequest{

  string event_id = 1;

  Subject subject = 2;

}

message MatcherResult {
    string id_subject = 1;
    float matcher_score = 2;
}

message FacialVerificationResponse{

  enum ResponseType {
    SUCCESS = 0;
    ERROR = 1;
    NOT_FOUND = 2;
  }

  string message = 1;

  ResponseType type = 2;

  MatcherResult matcher_result = 3;
}

And here is the code:

try{
    strResponse = rpcClient.call(facialRequest.toByteArray());
    System.out.println(strResponse);
    String value = new String(strResponse.getBytes(), StandardCharsets.UTF_8);

    Verification.FacialVerificationResponse response = Verification.FacialVerificationResponse.parseFrom(
                    strResponse.getBytes());

    System.out.println(response);
    }
catch (Exception e){
        e.printStackTrace();
    }

And the StackTrace:

com.google.protobuf.InvalidProtocolBufferException$InvalidWireTypeException: Protocol message tag had invalid wire type.
    at com.google.protobuf.InvalidProtocolBufferException.invalidWireType(InvalidProtocolBufferException.java:111)
    at com.google.protobuf.UnknownFieldSet$Builder.mergeFieldFrom(UnknownFieldSet.java:557)
    at com.google.protobuf.GeneratedMessageV3.parseUnknownField(GeneratedMessageV3.java:320)
    at model.Verification$FacialVerificationResponse.<init>(Verification.java:1543)
    at model.Verification$FacialVerificationResponse.<init>(Verification.java:1473)
    at model.Verification$FacialVerificationResponse$1.parsePartialFrom(Verification.java:2403)
    at model.Verification$FacialVerificationResponse$1.parsePartialFrom(Verification.java:2397)
    at com.google.protobuf.AbstractParser.parsePartialFrom(AbstractParser.java:158)
    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:191)
    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:203)
    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:208)
    at com.google.protobuf.AbstractParser.parseFrom(AbstractParser.java:48)
    at model.Verification$FacialVerificationResponse.parseFrom(Verification.java:1888)
    at controllers.VerificationController.index(VerificationController.java:36)
    [...]
1 Answers

I was sending the bytes of a String, while I should the bytes of FacialVerificationResponse, so this was the error.

Related