PackedLen in the string binary representation

  • Thread starter Thread starter Wiktor Zychla
  • Start date Start date
W

Wiktor Zychla

Hi there,

when stored in the binaries (or in metadata), strings are represented in
a special format: the length is followed by the string data.

However, I do not quite understand this PackedLen value that precedes
consecutive bytes. I've made some experiments and figured out that 8-bit
numbers are stored as they are (single byte) and numbers greater than 255
are stored on 2 bytes with trailing 8 (for example 1495 is 85D7).

Could anyone explain this PackedLen format to me? Is it some kind of
standard? Unfortunately, I have no idea what the google should be asked for.

Regards,
Wiktor Zychla
 
Wiktor,
Could anyone explain this PackedLen format to me? Is it some kind of
standard? Unfortunately, I have no idea what the google should be asked for.

The length is a compressed integer, stored using the compression
algorithm used in many other places in metadata. It's described in
Partition II, 22.2. Basicly it goes like this

If value is 0-127, store it in the 7 least significant bits in a
single byte, and set the MSB to 0).
If value is 128-0x3fff, store it in the 14 least significant bits of a
16-bit word, and set the two high bits to binary 10. This is what
you're seeing - the 8 comes from the high nibble being 1000.
Otherwise (if value is 0x4000-0x1fffffff) store in a 32-bit word with
the three high bits set to binary 110.



Mattias
 
Otherwise (if value is 0x4000-0x1fffffff) store in a 32-bit word with
the three high bits set to binary 110.

this is what I was looking for. thanks a lot, Mattias.

Regards,
Wiktor
 
Back
Top