private static byte[] GetIntegerBytes(long value)
{
// See AddIntegerCount() for why this is restricting use
// of the most significant bit.
if (value >= 0 && value < 128)
{
return new byte[] { (byte)value };
}
else if (value >= short.MinValue && value <= short.MaxValue)
{
return BitConverter.GetBytes(((short)value).ToBigEndianConditional());
}
else if (value >= int.MinValue && value <= int.MaxValue)
{
return BitConverter.GetBytes(((int)value).ToBigEndianConditional());
}
else
{
return BitConverter.GetBytes(value.ToBigEndianConditional());
}
}