public void TestGetBuffer0() { clearPacket(); var buffer = packet.GetBuffer(10); Assert.IsTrue((buffer == null) || (buffer.Length == 0)); }
public static int ReadInt32(IBufferPacket packet) { var dataSize = 4; var data = packet.GetBuffer(dataSize); if (data == null || data.Length < dataSize) { return(-1); } IntPtr p = Marshal.AllocHGlobal(dataSize); Marshal.Copy(data, 0, p, dataSize); var result = Marshal.ReadInt32(p); Marshal.FreeHGlobal(p); return(result); }
public static StspOperation ReadOption(IBufferPacket packet) { var dataSize = 8; var data = packet.GetBuffer(dataSize); if (data == null || data.Length < dataSize) { return(StspOperation.StspOperation_Unknown); } IntPtr p = Marshal.AllocHGlobal(dataSize); Marshal.Copy(data, 0, p, dataSize); var result = Marshal.ReadInt32(p, 4); Marshal.FreeHGlobal(p); if (result < (int)StspOperation.StspOperation_Unknown || result > (int)StspOperation.StspOperation_Last) { return(StspOperation.StspOperation_Unknown); } return((StspOperation)result); }