Esempio n. 1
0
        internal static float ReadVarSingle(BinaryReader reader)
        {
            var input = reader.ReadByte();

            var buff = SharedArray.Get();

            var embedded = (input & FlagEmbedded) == FlagEmbedded;

            if (embedded)
            {
                SharedArray.ClearArray4();

                // last byte
                buff[3] = (byte)(input & MaskEmbedded);
                return(BitConverter.ToSingle(buff, 0));
            }

            int length = input;

            if (length < 4)
            {
                SharedArray.ClearArray4();
            }

            reader.Read(buff, 4 - length, length);

            return(BitConverter.ToSingle(buff, 0));
        }
Esempio n. 2
0
        private static byte[] ConvertToVarBinary(int value, out byte length)
        {
            if (value < 0)
            {
                length = 4;
                var buff = SharedArray.Get();
                buff[0] = (byte)value;
                buff[1] = unchecked ((byte)(value >> 8));
                buff[2] = unchecked ((byte)(value >> 16));
                buff[3] = unchecked ((byte)(value >> 24));
                return(buff);
            }
            else
            {
                var buff = SharedArray.Get();
                SharedArray.ClearArray4();

                var num1 = (byte)value;
                var num2 = unchecked ((byte)(value >> 8));
                var num3 = unchecked ((byte)(value >> 16));
                var num4 = unchecked ((byte)(value >> 24));


                buff[0] = num1;

                if (num2 > 0)
                {
                    buff[1] = num2;
                }
                else if (num3 == 0 && num4 == 0)
                {
                    length = 1;
                    return(buff);
                }

                if (num3 > 0)
                {
                    buff[2] = num3;
                }
                else if (num4 == 0)
                {
                    length = 2;
                    return(buff);
                }

                if (num4 > 0)
                {
                    buff[3] = num4;
                }
                else
                {
                    length = 3;
                    return(buff);
                }
                length = 4;
                return(buff);
            }
        }