Can a Protobuf message begin with a gzip magic number?

Viewed 500

When I transmit a Protobuf message optionally compressed with gzip, can I trust that if the message begins with the gzip magic number (0x1f8b) it is the compressed version?
In other words, is it possible that a Protobuf message will begin with 0x1f8b, so my detection method would fail, therefore I would have to prepend a marker flag to explicitly indicate the compression?

1 Answers

Hex 1f is binary 11111 which, in protobuf varint/field-header terms, is a single byte integer. The lowest 3 bits of a field-header is the wire type, so this would be wire type 7. But, THERE IS NO WIRE TYPE 7. So: hex 1f is not a valid field header and therefore cannot be the first byte of a valid protobuf message.

So: if you see the gzip magic number, it is definitely not a protobuf message that looks similar.

Related