I have 2 protobuf messages that I am unable to decode unless I remove some bytes from the beginning and/or from the end.
First message in base64 is:
RQAAAPEmCgV0ZXN0MRAXGbj4KzKrldhBIAFCAQBKAQBRAAEAsPC/WQAAAAAAAPC/
which translates to this byte array:
45 00 00 00 f1 26 0a 05 74 65 73 74 31 10 17 19 b8 f8 2b 32 ab 95 d8 41 20 01 42 01 00 4a 01 00 51 00 01 00 b0 f0 bf 59 00 00 00 00 00 00 f0 bf
If I call Google's protobuf Parser.ParseFrom(<above byte array>)
it fails with the exception "Protocol message contained a tag with an invalid wire type."
But if I skip the first 6 bytes and the last 7 (so basically 0a 05 74 65 73 74 31 10 17 19 b8 f8 2b 32 ab 95 d8 41 20 01 42 01 00 4a 01 00 51 00 01 00 b0 f0 bf 59 00) then it works.
Alternatively, if I call Parser.ParseDelimitedFrom(<stream of the complete byte array>)
again, same story, unless I remove 4 bytes (not 6) this time from the beginning and 7 from the end (f1 26 0a 05 74 65 73 74 31 10 17 19 b8 f8 2b 32 ab 95 d8 41 20 01 42 01 00 4a 01 00 51 00 01 00 b0 f0 bf 59 00)
The second message is:
RgAAAPA3CgV0ZXN0MhAmGdimrTmrldhBIAFCAQBKAgABUfYOIizeJGRAWYxpKU8HvFFA
or
46 00 00 00 f0 37 0a 05 74 65 73 74 32 10 26 19 d8 a6 ad 39 ab 95 d8 41 20 01 42 01 00 4a 02 00 01 51 f6 0e 22 2c de 24 64 40 59 8c 69 29 4f 07 bc 51 40
which behaves the same as the first message except that for this one I don't need to remove any bytes from the end, only 6 and 4 from the beginning for Parser.ParseFrom
and Parser.ParseDelimitedFrom
respectively to work.
Can someone please explain to me what's going on? Does it have something to do with CodedInputStream?