internal static void WriteCompressedSignedInteger(ref BlobWriter writer, int value)
        {
            unchecked
            {
                const int b6  = (1 << 6) - 1;
                const int b13 = (1 << 13) - 1;
                const int b28 = (1 << 28) - 1;

                // 0xffffffff for negative value
                // 0x00000000 for non-negative
                int signMask = value >> 31;

                if ((value & ~b6) == (signMask & ~b6))
                {
                    int n = ((value & b6) << 1) | (signMask & 1);
                    writer.WriteByte((byte)n);
                }
                else if ((value & ~b13) == (signMask & ~b13))
                {
                    int n = ((value & b13) << 1) | (signMask & 1);
                    writer.WriteUInt16BE((ushort)(0x8000 | n));
                }
                else if ((value & ~b28) == (signMask & ~b28))
                {
                    int n = ((value & b28) << 1) | (signMask & 1);
                    writer.WriteUInt32BE(0xc0000000 | (uint)n);
                }
                else
                {
                    Throw.ValueArgumentOutOfRange();
                }
            }
        }
Exemplo n.º 2
0
 internal static void WriteCompressedInteger(ref BlobWriter writer, uint value)
 {
     unchecked
     {
         if (value <= SingleByteCompressedIntegerMaxValue)
         {
             writer.WriteByte((byte)value);
         }
         else if (value <= TwoByteCompressedIntegerMaxValue)
         {
             writer.WriteUInt16BE((ushort)(0x8000 | value));
         }
         else if (value <= MaxCompressedIntegerValue)
         {
             writer.WriteUInt32BE(0xc0000000 | value);
         }
         else
         {
             Throw.ValueArgumentOutOfRange();
         }
     }
 }
 internal static void WriteCompressedInteger(ref BlobWriter writer, uint value)
 {
     unchecked
     {
         if (value <= SingleByteCompressedIntegerMaxValue)
         {
             writer.WriteByte((byte)value);
         }
         else if (value <= TwoByteCompressedIntegerMaxValue)
         {
             writer.WriteUInt16BE((ushort)(0x8000 | value));
         }
         else if (value <= MaxCompressedIntegerValue)
         {
             writer.WriteUInt32BE(0xc0000000 | value);
         }
         else
         {
             Throw.ValueArgumentOutOfRange();
         }
     }
 }
Exemplo n.º 4
0
        internal static void WriteCompressedSignedInteger(ref BlobWriter writer, int value)
        {
            unchecked
            {
                const int b6 = (1 << 6) - 1;
                const int b13 = (1 << 13) - 1;
                const int b28 = (1 << 28) - 1;

                // 0xffffffff for negative value
                // 0x00000000 for non-negative
                int signMask = value >> 31;

                if ((value & ~b6) == (signMask & ~b6))
                {
                    int n = ((value & b6) << 1) | (signMask & 1);
                    writer.WriteByte((byte)n);
                }
                else if ((value & ~b13) == (signMask & ~b13))
                {
                    int n = ((value & b13) << 1) | (signMask & 1);
                    writer.WriteUInt16BE((ushort)(0x8000 | n));
                }
                else if ((value & ~b28) == (signMask & ~b28))
                {
                    int n = ((value & b28) << 1) | (signMask & 1);
                    writer.WriteUInt32BE(0xc0000000 | (uint)n);
                }
                else
                {
                    Throw.ValueArgumentOutOfRange();
                }
            }
        }