public ClientIncomingPacket Decode(byte[] data, int length) { var reusableIncoming = new ClientIncomingPacket(); _buffer.Load(data, length); _buffer.DecodePacket(reusableIncoming, _pools.EventTypeCompressor, typeCode => _pools.CreateEvent(typeCode), (buffer, packet) => { // Read: [Deltas] buffer.Decode(packet.ReceivedDeltas, () => { //var delta = buffer.DecodeDelta(packet.SenderTick); var packetTick = packet.SenderTick; var delta = _pools.DeltaPool.Allocate(); State state = null; // Read: [EntityId] var entityId = buffer.ReadEntityId(); // Read: [IsFrozen] var isFrozen = buffer.ReadBool(); if (!isFrozen) { // Read: [FactoryType] var typeCode = buffer.ReadInt(_pools.EntityTypeCompressor); state = _pools.CreateState(typeCode); // Read: [IsRemoved] var isRemoved = buffer.ReadBool(); if (isRemoved) { // Read: [DestroyedTick] state.RemovedTick = buffer.ReadTick(); // End Read } else { // Read: [HasControllerData] state.HasControllerData = buffer.ReadBool(); // Read: [HasImmutableData] state.HasImmutableData = buffer.ReadBool(); // Read: [Flags] state.Flags = buffer.Read(state.FlagBits); // Read: [Mutable Data] DecodeMutableData(state.Flags, state); if (state.HasControllerData) { // Read: [Controller Data] DecodeControllerData(state); // Read: [Command Ack] state.CommandAck = buffer.ReadTick(); } if (state.HasImmutableData) { // Read: [Immutable Data] DecodeImmutableData(state); } } } delta.Initialize(packetTick, entityId, state, isFrozen); return(delta); }); }); if (_buffer.IsFinished) { return(reusableIncoming); } else { return(default);