I've been reading up on Google Protocol Buffers recently, which allows for a variety of scalar value types to be used in messages.
According to their documentation, there's three types of variable-length integer primitives - int32
, uint32
, and sint32
. In their documentation, they note that int32
is "Inefficient for encoding negative numbers – if your field is likely to have negative values, use sint32
instead." But if you have a field that has no negative numbers, I assume that uint32 would be a better type to use than int32
anyways (due to the extra bit and decreased CPU cost of processing negative numbers).
So when would int32
be a good scalar to use? Is the documentation implying that it's most efficient only when you rarely get negative numbers? Or is it always preferable to use sint32
and uint32
, depending on the contents of the field?
(The same questions apply to the 64-bit versions of these scalars as well: int64
, uint64
, and sint64
; but I left them out of the problem description for readability's sake.)