public void WriteDecimal(decimal value)
{
var ints = decimal.GetBits(value);
var header = (byte)((ints[3] >> 16) & 31);
if (ints[3] < 0) header |= 128;
var first = (uint)ints[0] + ((ulong)ints[1] << 32);
if (ints[2] == 0)
{
if (first == 0)
{
WriteUInt8(header);
}
else
{
header |= 32;
WriteUInt8(header);
WriteVUInt64(first);
}
}
else
{
if ((uint)ints[2] < 0x10000000)
{
header |= 64;
WriteUInt8(header);
WriteVUInt32((uint)ints[2]);
WriteInt64((long)first);
}
else
{
header |= 64 | 32;
WriteUInt8(header);
WriteInt32(ints[2]);
WriteInt64((long)first);
}
}
}