Protobuf error:Protocol message tag had invalid wire type

前端 未结 2 1964
遥遥无期
遥遥无期 2021-01-02 01:28

I am having the following error when trying to read the message in java

Exception in thread \"main\" com.google.protobuf.InvalidProtocolBufferException: Prot         


        
2条回答
  •  我在风中等你
    2021-01-02 01:54

    I very much doubt that you're getting the exception there - I'd expect you to get it in parseFrom. Could you post the full stack trace instead of just the first three lines?

    I strongly suspect you've basically got a broken file. The fact that you've given a .txt extension for what should be a binary file is somewhat suspect... what does the file actually look like? You don't use parseFrom like this to parse an ASCII representation of a protobuf message.

    EDIT: As per the question linked in the comment, you're trying to parse a text file using a method designed for binary data.

    You want to use something like:

    // Use the normal try/finally for closing reliably
    InputStreamReader reader = new InputStreamReader(fis, "ASCII");
    
    Nt.Builder builder = Nt.newBuilder();
    TextFormat.merge(reader, builder);
    Nt nt = builder.build();
    

提交回复
热议问题