On Jul 16, 2:10 am, "James Bruce" <
james.br...@gmail.com> wrote:
> Nevertheless, it would be nice to have them for the in-memory version.
> My use cases have variables that would almost never exceed a single
> digit, so it would be nice to keep those small (and sorted to minimize
> waste from alignment). The nice thing about all those types being
> varint on the wire is that you can always safely promote a type and
> keep compatibility, which also means that you don't have to go
> overboard with future-proofing (i.e. making everything 64 bit "just in
> case").
Hm. You could run an incoming message through the deserializer,
convert that data to int8/int16's, store it along with the others,
repeat. That way, only the incoming message has int32-wide fields.
But that only works if you're storing a lot of messages with a few
fields each. Here we have yet another use case for a streaming
deserializer - int32's could get squeezed into int8/int16's on the
fly, instead of waiting for the whole message to be parsed.
From my calculations, numbers <= 127 will take one byte, numbers <=
16,383 (127+127*128) will take two, numbers <= 2,097,151
(127+127*128+127*128^2) will take three. The normal range for int8's
and int16's are up to 255 and 65,536, respectively. So my mistake,
int16's that are 16,383-65,536 will take three bytes.