Ejemplo n.º 1
0
 /// <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;
 }
Ejemplo n.º 2
0
        /// <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
            };

        }
Ejemplo n.º 3
0
 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));
     }
 }
Ejemplo n.º 4
0
 /// <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;
 }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
 /// <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;
 }
Ejemplo n.º 7
0
 /// <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;
 }
Ejemplo n.º 8
0
 /// <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;
 }
Ejemplo n.º 9
0
 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;
 }
Ejemplo n.º 10
0
 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);
     }
 }