/// <summary> /// Initializes a new instance of the <see cref="PacketData"/> class. /// </summary> /// <param name="data">The data.</param> /// <param name="options">The options.</param> public PacketData(byte[] data, PacketOptions options) { _data = data; _mem = new MemoryStream(data); _read = new BinaryReader(_mem); _options = options; }
/// <summary> /// Initializes a new instance of the <see cref="AndroidRemote"/> class. /// </summary> /// <param name="socket">The socket.</param> public AndroidRemote(TcpClient socket) { NetworkStream = socket.GetStream(); PacketWriter = new PacketWriter(this); PacketReader = new PacketReader(this); PacketOptions = new PacketOptions() { UseBigEndian = true, UseShortAsHeaderSize = true }; }
public static byte[] GetLength(int p, PacketOptions packetOptions) { if (packetOptions.UseShortAsHeaderSize) { return(BitConverter.GetBytes(packetOptions.UseBigEndian ? IPAddress.HostToNetworkOrder(p) : p)); } else { return(BitConverter.GetBytes(packetOptions.UseBigEndian ? IPAddress.HostToNetworkOrder((short)p) : (short)p)); } }
/// <summary> /// Initializes a new instance of the <see cref="PacketData"/> class. /// </summary> /// <param name="options">The options.</param> public PacketData(PacketOptions options) { _mem = new MemoryStream(); _write = new BinaryWriter(_mem); _options = options; }
internal static int GetLength(System.Net.Sockets.NetworkStream networkStream, PacketOptions packetOptions) { byte[] data = new byte[packetOptions.UseShortAsHeaderSize ? 2 : 4]; networkStream.Read(data, 0, data.Length); var toInt = packetOptions.UseShortAsHeaderSize ? (short)BitConverter.ToInt16(data, 0) : BitConverter.ToInt32(data, 0); if (packetOptions.UseBigEndian) { toInt = packetOptions.UseBigEndian ? IPAddress.HostToNetworkOrder((short)toInt) : IPAddress.HostToNetworkOrder(toInt); } return(toInt); }
/// <summary> /// Initializes a new instance of the <see cref="PacketReader"/> class. /// </summary> /// <param name="c">The remote.</param> public PacketReader ( IRemote c ) { mReader = new BinaryReader( c.NetworkStream ); this.remote = c; options = c.PacketOptions; }
/// <summary> /// Initializes a new instance of the <see cref="PacketData"/> class. /// </summary> /// <param name="options">The options.</param> public PacketData(PacketOptions options) { _mem = new MemoryStream(); _write = new BinaryWriter(_mem); _options = options; }
/// <summary> /// Initializes a new instance of the <see cref="PacketData"/> class. /// </summary> /// <param name="data">The data.</param> /// <param name="options">The options.</param> public PacketData(byte[] data, PacketOptions options) { _data = data; _mem = new MemoryStream(data); _read = new BinaryReader(_mem); _options = options; }
internal static int GetLength(System.Net.Sockets.NetworkStream networkStream, PacketOptions packetOptions) { byte[] data = new byte[packetOptions.UseShortAsHeaderSize ? 2 : 4]; networkStream.Read(data, 0, data.Length); var toInt = packetOptions.UseShortAsHeaderSize ? (short)BitConverter.ToInt16(data, 0) : BitConverter.ToInt32(data, 0); if (packetOptions.UseBigEndian) toInt = packetOptions.UseBigEndian ? IPAddress.HostToNetworkOrder((short)toInt) : IPAddress.HostToNetworkOrder(toInt); return toInt; }
public static byte[] GetLength(int p, PacketOptions packetOptions) { if (packetOptions.UseShortAsHeaderSize) { return BitConverter.GetBytes(packetOptions.UseBigEndian ? IPAddress.HostToNetworkOrder(p) : p); } else { return BitConverter.GetBytes(packetOptions.UseBigEndian ? IPAddress.HostToNetworkOrder((short)p) : (short)p); } }