NuoDb.Data.Client.EncodedDataStream.encodeOldBigDecimal C# (CSharp) Method

encodeOldBigDecimal() public method

public encodeOldBigDecimal ( decimal bd ) : void
bd decimal
return void
        public virtual void encodeOldBigDecimal(decimal bd)
        {
            int scale;
            Decimal temp;
            ConvertToScaledDecimal(bd, out scale, out temp);
            int neg = bd.CompareTo(decimal.Zero) == -1 ? 1 : 0;

            // The server expects a byte array with a signed first byte.
            // BigInteger.toByteArray() creates an array of the value in two's compliment.
            // So get the unsigned value and set the sign bit manually.

            BigInteger bi = new BigInteger(Decimal.Truncate(Math.Abs(temp)).ToString(), 10);
            byte[] byteArray = bi.ToByteArray();

            if (neg == 1)
            {
                byteArray[0] |= 0x80;
            }

            write(edsScaledCount1);
            write(byteArray.Length + 1);
            write(scale);
            write(byteArray);
        }