Esempio n. 1
0
        private void EventDataIsSerialized()
        {
            Event instance0 = (Event)eventCreator.Object.CreateEvent(iFactoryType);

            instance0.Attempts = 1;
            instance0.Data     = 43;
            instance0.EventId  = SequenceId.Start + 44;
            eventCreator.Verify(m => m.CreateEvent(iFactoryType), Times.Once());

            // Encode to buffer
            RailBitBuffer buffer = new RailBitBuffer();

            instance0.Encode(eventCreator.Object.EventTypeCompressor, buffer, Tick.START);

            // Read from buffer
            RailEvent instance1Base = RailEvent.Decode(
                eventCreator.Object,
                eventCreator.Object.EventTypeCompressor,
                buffer,
                Tick.START);

            eventCreator.Verify(m => m.CreateEvent(iFactoryType), Times.Exactly(2));
            Assert.Equal(instance0.EventId, instance1Base.EventId);
            Assert.IsType <Event>(instance0);
            Assert.Equal(instance0.Data, ((Event)instance1Base).Data);
        }
Esempio n. 2
0
        private static void DecodeEvents(
            RailPacketIncoming packet,
            IRailEventConstruction eventCreator,
            RailBitBuffer buffer)
        {
            IEnumerable <RailEvent> decoded = buffer.UnpackAll(
                buf => RailEvent.Decode(
                    eventCreator,
                    eventCreator.EventTypeCompressor,
                    buf,
                    packet.SenderTick));

            foreach (RailEvent evnt in decoded)
            {
                packet.Events.Add(evnt);
            }
        }