Lengths in OSHS binaries

Some of the OSHS binary file formats use somewhat strange length specifications. They are only 8-bit but allow the user to specify sizes up to 4GB. The actual 32 bit value may be computed from the 8 bit one using this function:

uint32 UnpackLength(uint32 Length)
{
  uint32 Count;
  uint32 Shift;
  uint32 Add;

  Count=(Length % 16) + 1;
  Shift=Length / 16;
  Add=((1 << Shift) - 1) << 16;
  return((Count << (Shift + 12)) + Add);
}