Example #1
0
        public static RailCommandUpdate Decode(
            IRailCommandConstruction commandCreator,
            RailBitBuffer buffer)
        {
            RailCommandUpdate update = commandCreator.CreateCommandUpdate();

            // Read: [EntityId]
            update.EntityId = buffer.ReadEntityId();

            // Read: [Count]
            int count = (int)buffer.Read(BUFFER_COUNT_BITS);

            // Read: [Commands]
            for (int i = 0; i < count; i++)
            {
                update.commands.Store(RailCommand.Decode(commandCreator, buffer));
            }

            return(update);
        }
Example #2
0
        private void DecodeReadsTickAndCommandData(int iData)
        {
            RailMemoryPool <RailCommand> pool =
                new RailMemoryPool <RailCommand>(new RailFactory <TestUtils.Command>());
            Mock <IRailCommandConstruction> mockCreator = new Mock <IRailCommandConstruction>();

            mockCreator.Setup(m => m.CreateCommand()).Returns(pool.Allocate());

            RailBitBuffer bitBuffer   = new RailBitBuffer(2);
            Tick          writtenTick = Tick.START.GetNext();

            bitBuffer.WriteTick(writtenTick);
            bitBuffer.WriteInt(iData);

            RailCommand decodedGenericCommand = RailCommand.Decode(mockCreator.Object, bitBuffer);

            Assert.IsType <TestUtils.Command>(decodedGenericCommand);
            TestUtils.Command decodedCommand = decodedGenericCommand as TestUtils.Command;
            Assert.NotNull(decodedCommand);
            Assert.Equal(writtenTick, decodedCommand.ClientTick);
            Assert.Equal(iData, decodedCommand.Data);
        }