As Adam said, -1 has a representation that is not just a single 0xFF. To
decode a varint, you have to read the bytes until the most significant bit
is 0. (See
http://code.google.com/apis/protocolbuffers/docs/encoding.html#varints)
Note that int32 values are sign-extended for wire compatibility with int64,
so you will get a 10-byte varint.
On Thu, Jan 13, 2011 at 3:49 AM, Adam Skutt ask...@gmail.com wrote:
On Jan 13, 2:23 am, 飞 杨 youngphy.y...@dianping.com wrote:
Dear sir,
I found, in the protocolbuf int encode, the byte 0xFF may appear, then
how can i distinguish the EOS and the business -1, the two both are -1
when use the inputstream.read()..
Pay closer attention to the definition of InputStream.read(). The
return type is an int, which is 32-bits. '-1' and 0x00FF are
distinct values. Make the check before casting the return value to an
byte. That being said, I wouldn't read data one byte at a time either
without a good reason.
Adam
--
You received this message because you are subscribed to the Google Groups
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to
protobuf+unsubscr...@googlegroups.comprotobuf%2bunsubscr...@googlegroups.com
.
For more options, visit this group at
http://groups.google.com/group/protobuf?hl=en.
--
You received this message because you are subscribed to the Google Groups
Protocol Buffers group.
To post to this group, send email to protobuf@googlegroups.com.
To unsubscribe from this group, send email to
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/protobuf?hl=en.