/// <summary> /// Reads in 2 bytes and converts it from network to host byte order /// </summary> /// <returns>A 2 byte (short) value</returns> public virtual ushort ReadShort() { var v1 = (byte)ReadByte(); var v2 = (byte)ReadByte(); return(Marshal.ConvertToUInt16(v1, v2)); }
/// <summary> /// Reads in 2 bytes /// </summary> /// <returns>A 2 byte (short) value in network byte order</returns> public virtual ushort ReadShortLowEndian() { var v1 = (byte)ReadByte(); var v2 = (byte)ReadByte(); return(Marshal.ConvertToUInt16(v2, v1)); }
/// <summary> /// Constructor /// </summary> /// <param name="buf">Buffer containing packet data to read from</param> /// <param name="start">Starting index into buf</param> /// <param name="size">Number of bytes to read from buf</param> public PacketIn(byte[] buf, int start, int size) : base(size) { m_psize = Marshal.ConvertToUInt32(buf, start) - HDR_SIZE; m_id = Marshal.ConvertToUInt16(buf, start + 4); m_checksum = buf[start + 6]; Position = 0; Write(buf, start + 7, size - HDR_SIZE); SetLength(size - HDR_SIZE); Position = 0; }