Exemplo n.º 1
0
        public Packet Read()
        {
            byte[] buffer = new byte[_bufferSize];

            _connection.Read(buffer, Header.size);
            var header = new Header();
            header.Deserialize(buffer);
            _connection.Read(buffer, header.bodySize);
            return Packet.Create(header, buffer);
        }
Exemplo n.º 2
0
        public void Deserialize(byte[] buffer)
        {
            int offset = 0;

            int count = Serializer.ToInt32(buffer, offset);
            offset += Serializer.SerializedSize(count);

            _list.Clear();

            var bytes = new byte[1024];
            for (int i = 0; i < count; i++)
            {
                Array.Copy(buffer, offset, bytes, 0, Header.size);
                var header = new Header();
                header.Deserialize(bytes);
                offset += Header.size;
                Array.Copy(buffer, offset, bytes, 0, header.bodySize);
                var packet = Packet.Create(header, bytes);
                offset += header.bodySize;
                _list.Add((ItemStack)packet.body);
            }
        }
Exemplo n.º 3
0
 public static Packet ToPacket(byte[] buffer, int offset)
 {
     byte[] bytes = new byte[Header.size];
     Buffer.BlockCopy(buffer, offset, bytes, 0, Header.size);
     Header header = new Header();
     header.Deserialize(bytes);
     offset += Header.size;
     bytes = new byte[header.bodySize];
     Buffer.BlockCopy(buffer, offset, bytes, 0, header.bodySize);
     return Packet.Create(header, bytes);
 }
Exemplo n.º 4
0
 public static Packet Create(Header header, byte[] bytes)
 {
     IAutoSerializable body = (IAutoSerializable)Activator.CreateInstance(GetTypeByIndex(header.type));
     body.Deserialize(bytes);
     return new Packet(header, body);
 }
Exemplo n.º 5
0
 Packet(Header header, IAutoSerializable body)
 {
     this.header = header;
     this.body = body;
 }
Exemplo n.º 6
0
 public Packet(IAutoSerializable body)
 {
     header = body.CreateHeader();
     this.body = body;
 }