Ejemplo n.º 1
0
 public static Foo Decode(this RailBitBuffer buffer)
 {
     return(new Foo()
     {
         A = buffer.ReadInt(),
         B = buffer.ReadInt()
     });
 }
Ejemplo n.º 2
0
        public static MethodCall ReadMethodCall(this RailBitBuffer buffer)
        {
            MethodCall pack = new MethodCall();

            pack.Id       = new MethodId(buffer.ReadInt());
            pack.Instance = buffer.DecodeEventArg();
            int iNumberOfArguments = buffer.ReadInt();

            for (int i = 0; i < iNumberOfArguments; ++i)
            {
                pack.Arguments.Add(buffer.DecodeEventArg());
            }

            return(pack);
        }
Ejemplo n.º 3
0
        private void ReadWriteInt(int expected)
        {
            RailBitBuffer buffer = new RailBitBuffer();

            buffer.WriteInt(expected);
            long actual = buffer.ReadInt();

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 4
0
        private void EncodeWritesTickAndCommandData(int iData)
        {
            RailBitBuffer bitBuffer = new RailBitBuffer(2);

            TestUtils.Command command = new TestUtils.Command(iData)
            {
                ClientTick   = Tick.START,
                IsNewCommand = true
            };
            ((IRailPoolable <RailCommand>)command).Allocated();
            command.Encode(bitBuffer);

            Tick writtenTick = bitBuffer.ReadTick();
            int  writtenData = bitBuffer.ReadInt();

            Assert.Equal(Tick.START, writtenTick);
            Assert.Equal(iData, writtenData);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Note that the packetTick may not be the tick this event was created on
        ///     if we're re-trying to send this event in subsequent packets. This tick
        ///     is intended for use in tick diffs for compression.
        /// </summary>
        public static RailEvent Decode(
            IRailEventConstruction eventCreator,
            RailIntCompressor compressor,
            RailBitBuffer buffer,
            Tick packetTick)
        {
            // Read: [EventType]
            int factoryType = buffer.ReadInt(compressor);

            RailEvent evnt = eventCreator.CreateEvent(factoryType);

            // Read: [EventId]
            evnt.EventId = buffer.ReadSequenceId();

            // Read: [EventData]
            evnt.DataSerializer.ReadData(buffer, packetTick);

            return(evnt);
        }
Ejemplo n.º 6
0
        public static Argument DecodeEventArg(this RailBitBuffer buffer)
        {
            EventArgType eType = (EventArgType)buffer.Read(NumberOfBitsForArgType);

            switch (eType)
            {
            case EventArgType.EntityReference:
                return(new Argument(buffer.ReadEntityId()));

            case EventArgType.MBGUID:
                return(new Argument(buffer.ReadMBGUID()));

            case EventArgType.Null:
                return(Argument.Null);

            case EventArgType.Int:
                return(new Argument(buffer.ReadInt()));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 7
0
 public void ReadData(RailBitBuffer buffer)
 {
     Data = buffer.ReadInt();
 }
Ejemplo n.º 8
0
 public int Read(RailBitBuffer buffer)
 {
     return(buffer.ReadInt(this));
 }
Ejemplo n.º 9
0
        public static RailStateDelta DecodeDelta(
            IRailStateConstruction stateCreator,
            RailBitBuffer buffer,
            Tick packetTick)
        {
            RailStateDelta delta = stateCreator.CreateDelta();
            RailState      state = null;

            Tick commandAck  = Tick.INVALID;
            Tick removedTick = Tick.INVALID;

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

            // Read: [IsFrozen]
            bool isFrozen = buffer.ReadBool();

            if (isFrozen == false)
            {
                // Read: [FactoryType]
                int factoryType = buffer.ReadInt(stateCreator.EntityTypeCompressor);
                state = stateCreator.CreateState(factoryType);

                // Read: [IsRemoved]
                bool isRemoved = buffer.ReadBool();

                if (isRemoved)
                // Read: [RemovedTick]
                {
                    removedTick = buffer.ReadTick();
                }

                // Read: [HasControllerData]
                state.HasControllerData = buffer.ReadBool();

                // Read: [HasImmutableData]
                state.HasImmutableData = buffer.ReadBool();

                if (state.HasImmutableData)
                // Read: [Immutable Data]
                {
                    state.DataSerializer.DecodeImmutableData(buffer);
                }

                // Read: [Flags]
                state.Flags = buffer.Read(state.DataSerializer.FlagBits);

                // Read: [Mutable Data]
                state.DataSerializer.DecodeMutableData(buffer, state.Flags);

                if (state.HasControllerData)
                {
                    // Read: [Controller Data]
                    state.DataSerializer.DecodeControllerData(buffer);

                    // Read: [Command Ack]
                    commandAck = buffer.ReadTick();
                }
            }

            delta.Initialize(packetTick, entityId, state, removedTick, commandAck, isFrozen);
            return(delta);
        }
Ejemplo n.º 10
0
        internal static RailStateDelta DecodeDelta(
            RailBitBuffer buffer,
            Tick packetTick)
        {
            RailStateDelta delta = RailResource.Instance.CreateDelta();
            RailState      state = null;

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

            // Read: [IsFrozen]
            bool isFrozen = buffer.ReadBool();

            if (isFrozen == false)
            {
                // Read: [FactoryType]
                int factoryType = buffer.ReadInt(RailState.FactoryTypeCompressor);
                state = RailState.Create(factoryType);

                // Read: [IsRemoved]
                bool 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]
                    state.DecodeMutableData(buffer, state.Flags);

                    if (state.HasControllerData)
                    {
                        // Read: [Controller Data]
                        state.DecodeControllerData(buffer);

                        // Read: [Command Ack]
                        state.CommandAck = buffer.ReadTick();
                    }

                    if (state.HasImmutableData)
                    {
                        // Read: [Immutable Data]
                        state.DecodeImmutableData(buffer);
                    }
                }
            }

            delta.Initialize(packetTick, entityId, state, isFrozen);
            return(delta);
        }
Ejemplo n.º 11
0
 protected override void DecodeImmutableData(RailBitBuffer buffer)
 {
     this.ArchetypeId = buffer.ReadInt();
     this.UserId      = buffer.ReadInt();
 }