Пример #1
0
 /// <summary>
 ///     Writes content of the message into a packet
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="packetToBeFilled"></param>
 /// <returns></returns>
 public T Deserialize <T>(T packetToBeFilled) where T : struct, ISerializablePacket
 {
     using (PooledNetReader r = NetReaderPool.GetReader(Buffer))
     {
         r.ReadInt16(); // This is the opcode that is still part of the data.
         packetToBeFilled.Deserialize(r);
         return(packetToBeFilled);
     }
 }
Пример #2
0
 /// <summary>
 ///     Deserialized data into the provided packet and returns it.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="data"></param>
 /// <param name="packet"></param>
 /// <returns></returns>
 public static T Deserialize <T>(int offset, ArraySegment <byte> data, T packet) where T : struct, ISerializablePacket
 {
     using (PooledNetReader r = NetReaderPool.GetReader(data))
     {
         r.Position = offset;
         packet.Deserialize(r);
         return(packet);
     }
 }
Пример #3
0
        /// <summary>
        ///     Constructs the message buffer into an incoming message.
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="sender"></param>
        /// <returns></returns>
        public static IncomingMessage FromBytes(ArraySegment <byte> buffer, Peer sender)
        {
            using (PooledNetReader r = NetReaderPool.GetReader(buffer))
            {
                var opCode = r.ReadInt16();
                var msg    = new IncomingMessage(opCode, buffer, sender /*, responseID, completeResponse, status*/);

                return(msg);
            }
        }
Пример #4
0
 public void Dispose()
 {
     NetReaderPool.Recycle(this);
 }