P
P
postflow2016-08-04 10:44:22
Android
postflow, 2016-08-04 10:44:22

Why doesn't protobuf understand array in parseFrom?

Trying to deserialize data using protobuf methods:
Googl says :

parseFrom(byte[] data);: разбирает сообщение из заданного массива байтов.

i pass it like this:
try {
                            Protocol.response response = Protocol.response.parseFrom(readBuf);
                        } catch (InvalidProtocolBufferException e) {
                            e.printStackTrace();
                        }

readBuf array - I get from the handler: At the same time, the readBuf array is NOT empty: [[email protected] only the 0th and 1st elements in the array have values: readBuf[0]8 readBuf[1]1 readBuf[2]0 ... etc to the end of the array. Here is a piece of the protofile (my.proto):
byte[] readBuf = (byte[]) msg.obj;
enum response_type {
    OK = 1;
    BUSY = 2;
    ERROR = 3;
}

message response {
    required response_type resp = 1;
}

And I keep getting an exception (in the logs):
...
W/System.err: com.google.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).
...
In response, as I understand it, OK or BUSY or ERROR should be assigned. Right?
UPD:
if I create an array by hand:
byte[] readBuf2 = { 8, 1, };
in response returns what you need (OK).
What are the differences between the lines? :
byte[] readBuf = (byte[]) msg.obj;
byte[] readBuf2 = { 8, 1, };

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question