Exemple #1
0
        public Int32 ReadInt32()
        {
            IntTypeFlag flag = (IntTypeFlag)_reader.ReadByte();

            if (flag == IntTypeFlag.Zero)
            {
                return(default(Int32));
            }
            Int32 ret;

            if ((flag & IntTypeFlag.BYTE) == IntTypeFlag.BYTE)
            {
                ret = _reader.ReadByte();
            }
            else if ((flag & IntTypeFlag.SHORT) == IntTypeFlag.SHORT)
            {
                ret = _reader.ReadUInt16();
            }
            else
            {
                ret = _reader.ReadInt32();
            }

            bool isMinus = (flag & IntTypeFlag.Minus) == IntTypeFlag.Minus;

            if (isMinus)
            {
                return(-ret);
            }
            return(ret);
        }
Exemple #2
0
        public Int32 ReadInt32()
        {
            IntTypeFlag flag = (IntTypeFlag)_reader.ReadByte();

            if (flag == IntTypeFlag.Zero)
            {
                return(default(Int32));
            }
            Int32 ret = _reader.ReadInt32();

            bool isMinus = (flag & IntTypeFlag.Minus) == IntTypeFlag.Minus;

            if (isMinus)
            {
                return(-ret);
            }
            return(ret);
        }
Exemple #3
0
        public void WriteInt32(Int32 num)
        {
            CheckBufferPoll(5);

            if (num == 0)
            {
                _ms.WriteByte((byte)IntTypeFlag.Zero);
                return;
            }
            IntTypeFlag flag = IntTypeFlag.DEFAULT;

            if (num < 0)
            {
                flag = IntTypeFlag.Minus;
                num  = Math.Abs(num);
            }
            byte[] byts = BitConverter.GetBytes(num);
            flag |= IntTypeFlag.INT;

            _ms.WriteByte((byte)flag);
            _ms.Write(byts, 0, byts.Length);
        }
        public void WriteInt32(Int32 num)
        {
            CheckBufferPoll(5);

            if (num == 0)
            {
                _ms.WriteByte((byte)IntTypeFlag.Zero);
                return;
            }
            IntTypeFlag flag = IntTypeFlag.DEFAULT;

            if (num < 0)
            {
                flag = IntTypeFlag.Minus;
                num  = Math.Abs(num);
            }
            byte[] byts = null;

            if (num <= byte.MaxValue)
            {
                byts  = new byte[] { (byte)num };
                flag |= IntTypeFlag.BYTE;
            }
            else if (num <= ushort.MaxValue)
            {
                byts  = BitConverter.GetBytes((ushort)num);
                flag |= IntTypeFlag.SHORT;
            }

            if (byts == null)
            {
                byts  = BitConverter.GetBytes(num);
                flag |= IntTypeFlag.INT;
            }

            _ms.WriteByte((byte)flag);
            _ms.Write(byts, 0, byts.Length);
        }