コード例 #1
0
ファイル: JetArray.cs プロジェクト: jetsons/JetPack.Net
        /// <summary>
        /// Writes a variable length floating point value to the stream.
        /// The number will use 2 to 9 bytes depending on its length.
        /// </summary>
        public void WriteVarDouble(double number, bool signed)
        {
            var length = VariableLength.GetVarDoubleLength(number, signed);

            WriteByte((byte)length);
            if (length == 1)
            {
                if (signed)
                {
                    WriteSByte((sbyte)number);
                }
                else
                {
                    WriteByte((byte)number);
                }
            }
            if (length == 2)
            {
                WriteUShort(VariableLength.EncodeDouble16(ReadUShort(), signed));
            }
            if (length == 4)
            {
                WriteUInt(VariableLength.EncodeDouble32(ReadUShort(), signed));
            }
            else
            {
                ReadDouble();
            }
        }
コード例 #2
0
ファイル: JetArray.cs プロジェクト: jetsons/JetPack.Net
        /// <summary>
        /// Reads a variable length floating point value from the stream.
        /// The number will use 2 to 9 bytes depending on its length.
        /// </summary>
        public double ReadVarDouble(bool signed)
        {
            int length = ReadByte();

            if (length == 1)
            {
                return(signed ? (double)ReadSByte() : (double)ReadByte());
            }
            if (length == 2)
            {
                return(VariableLength.DecodeDouble16(ReadUShort(), signed));
            }
            if (length == 4)
            {
                return(VariableLength.DecodeDouble32(ReadUShort(), signed));
            }
            else
            {
                return(ReadDouble());
            }
        }