예제 #1
0
        public void WriteVarLong(double @double)
        {
            var low = FinalInt64.FromNumber(@double);

            if (low.High != 0)
            {
                for (var i = 0; i < 4; i++)
                {
                    WriteByte((byte)((uint)low.Low & 127 | 128));
                    low.Low = (long)low.Low >> 7;
                }
                if ((low.High & 2147483640) != 0)
                {
                    WriteByte((byte)((low.High << 4 | (uint)low.Low) & 127 | 128));
                    WriteInt32((uint)(low.High >> 3));
                }
                else
                {
                    WriteByte((byte)(low.High << 4 | (uint)low.Low));
                }
            }
            else
            {
                WriteInt32((uint)low.Low);
            }
        }
예제 #2
0
        public FinalInt64 ReadVarInt64(BigEndianReader reader)
        {
            FinalInt64 finalInt64;
            var        low  = new FinalInt64();
            var        num1 = 0;

            while (true)
            {
                int num = reader.ReadByte();
                if (num1 == 28)
                {
                    if (num < 128)
                    {
                        low.Low    = (int)low.Low | num << (num1 & 31);
                        low.High   = num >> 4;
                        finalInt64 = low;
                        break;
                    }
                    num      = num & 127;
                    low.Low  = (uint)low.Low | num << (num1 & 31);
                    low.High = num >> 4;
                    num1     = 3;
                    while (true)
                    {
                        num = reader.ReadByte();
                        if (num1 < 32)
                        {
                            if (num < 128)
                            {
                                break;
                            }
                            low.High = low.High | (num & 127) << (num1 & 31);
                        }
                        num1 = num1 + 7;
                    }
                    low.High   = low.High | num << (num1 & 31);
                    finalInt64 = low;
                    break;
                }
                if (num < 128)
                {
                    low.Low    = (uint)low.Low | num << (num1 & 31);
                    finalInt64 = low;
                    break;
                }
                low.Low = (uint)low.Low | (num & 127) << (num1 & 31);
                num1    = num1 + 7;
            }
            return(finalInt64);
        }