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); }
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); } }
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); }
public static Packet Create(Header header, byte[] bytes) { IAutoSerializable body = (IAutoSerializable)Activator.CreateInstance(GetTypeByIndex(header.type)); body.Deserialize(bytes); return new Packet(header, body); }
Packet(Header header, IAutoSerializable body) { this.header = header; this.body = body; }
public Packet(IAutoSerializable body) { header = body.CreateHeader(); this.body = body; }