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); }
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); }
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); }