Example #1
0
    public static object Deserialize(StreamBuffer inStream, short length)
    {
        PlayerInputPacket inputPacket = new PlayerInputPacket();

        byte[] output = new byte[DataSize];

        inStream.Read(output, 0, DataSize);

        int index = 0;

        int frameSent;
        int packetId;
        int stringSize;

        Protocol.Deserialize(out frameSent, output, ref index);
        inputPacket.FrameSent = (uint)frameSent;

        Protocol.Deserialize(out packetId, output, ref index);
        inputPacket.PacketId = (uint)packetId;

        Protocol.Deserialize(out inputPacket.PlayerIndex, output, ref index);

        Protocol.Deserialize(out stringSize, output, ref index);
        byte[] customString = new byte[stringSize];
        inStream.Read(customString, 0, stringSize);

        string jsonString = Encoding.UTF8.GetString(customString);
        List <PlayerInputData> inputList = JsonConvert.DeserializeObject <List <PlayerInputData> >(jsonString);

        inputPacket.InputData = inputList;
        return(inputPacket);
    }
            public override int Read(byte[] buffer, int offset, int count)
            {
                ValidateBufferArguments(buffer, offset, count);
                ThrowIfDisposed();

                return(_readBuffer.Read(new Span <byte>(buffer, offset, count)));
            }
Example #3
0
        private object DeserializeCustom(StreamBuffer din, byte customTypeCode)
        {
            short      num        = this.DeserializeShort(din);
            CustomType customType = default(CustomType);

            if (Protocol.CodeDict.TryGetValue(customTypeCode, out customType))
            {
                if (customType.DeserializeStreamFunction == null)
                {
                    byte[] array = new byte[num];
                    din.Read(array, 0, num);
                    return(customType.DeserializeFunction(array));
                }
                int    position = din.IntPosition;
                object result   = customType.DeserializeStreamFunction(din, num);
                int    num2     = din.IntPosition - position;
                if (num2 != num)
                {
                    din.IntPosition = position + num;
                }
                return(result);
            }
            byte[] array2 = new byte[num];
            din.Read(array2, 0, num);
            return(array2);
        }
Example #4
0
        public static object QueueDeserialize(StreamBuffer inStream, short length)
        {
            var queue = new Queue <object>();

            lock (lengthMemory)
            {
                inStream.Read(lengthMemory, 0, 2);
                UInt16 queueLength = BitConverter.ToUInt16(lengthMemory, 0);

                while (queue.Count < queueLength)
                {
                    inStream.Read(lengthMemory, 0, 2);
                    UInt16 objLength = BitConverter.ToUInt16(lengthMemory, 0);

                    byte[] bytes = new byte[objLength];
                    inStream.Read(bytes, 0, objLength);

                    var obj = ByteArrayToObject(bytes);

                    queue.Enqueue(obj);
                }
            }

            return(queue);
        }
Example #5
0
            public override int Read(byte[] buffer, int offset, int count)
            {
                ValidateReadArrayArguments(buffer, offset, count);
                ThrowIfDisposed();
                ThrowIfReadingNotSupported();

                return _buffer.Read(new Span<byte>(buffer, offset, count));
            }
Example #6
0
            public override int Read(byte[] buffer, int offset, int count)
            {
                ThrowIfDisposed();
                ValidateArgs(buffer, offset, count);
                ThrowIfReadingNotSupported();

                return(_buffer.Read(new Span <byte>(buffer, offset, count)));
            }
        private static object DeserializeBooster(StreamBuffer inStream, short length)
        {
            if (length != memBoosterSize)
            {
                Debug.LogError("Length reveiced should be " + memBoosterSize);
            }

            Booster booster = ScriptableObject.CreateInstance <Booster>();

            lock (memBooster)
            {
                inStream.Read(memBooster, 0, length);
                int off = 0;

                int boosterType = -1;
                Protocol.Deserialize(out boosterType, memBooster, ref off);
                booster.type = (Booster.Type)boosterType;

                int boosterUseDuration = 0;
                Protocol.Deserialize(out boosterUseDuration, memBooster, ref off);
                booster.useDuration = Convert.ToBoolean(boosterUseDuration);

                Protocol.Deserialize(out booster.duration, memBooster, ref off);
                Protocol.Deserialize(out booster.strength, memBooster, ref off);
                Protocol.Deserialize(out booster.walkSpeedBooster, memBooster, ref off);
            }

            return(booster);
        }
Example #8
0
 public void EmptyBufferCanReadNoBytes()
 {
     using (StreamBuffer buffer = new StreamBuffer(0))
     {
         buffer.Read(new byte[0], 0, 1).Should().Be(0);
     }
 }
Example #9
0
        private object DeserializeCustom(StreamBuffer din, byte customTypeCode)
        {
            short      num = this.DeserializeShort(din);
            CustomType customType;
            bool       flag = Protocol.CodeDict.TryGetValue(customTypeCode, out customType);
            object     result;

            if (flag)
            {
                bool flag2 = customType.DeserializeStreamFunction == null;
                if (flag2)
                {
                    byte[] array = new byte[(int)num];
                    din.Read(array, 0, (int)num);
                    result = customType.DeserializeFunction(array);
                }
                else
                {
                    long   position = din.Position;
                    object obj      = customType.DeserializeStreamFunction(din, num);
                    int    num2     = (int)(din.Position - position);
                    bool   flag3    = num2 != (int)num;
                    if (flag3)
                    {
                        din.Position = position + (long)num;
                    }
                    result = obj;
                }
            }
            else
            {
                result = null;
            }
            return(result);
        }
        private static object DeserializeAsteroidDesc(StreamBuffer inStream, short length)
        {
            AsteroidDesc o = new AsteroidDesc();

            lock (memAsteroidDesc)
            {
                inStream.Read(memAsteroidDesc, 0, 4 * 10);
                int index = 0;
                Protocol.Deserialize(out o.Id, memAsteroidDesc, ref index);       //4
                Protocol.Deserialize(out o.Index, memAsteroidDesc, ref index);    //4
                var position = new Vector3();
                Protocol.Deserialize(out position.x, memAsteroidDesc, ref index); //4
                Protocol.Deserialize(out position.y, memAsteroidDesc, ref index); //4
                Protocol.Deserialize(out position.z, memAsteroidDesc, ref index); //4
                o.Position = position;

                var rotation = new Quaternion();

                Protocol.Deserialize(out rotation.x, memAsteroidDesc, ref index);  //4
                Protocol.Deserialize(out rotation.y, memAsteroidDesc, ref index);  //4
                Protocol.Deserialize(out rotation.z, memAsteroidDesc, ref index);  //4
                Protocol.Deserialize(out rotation.w, memAsteroidDesc, ref index);  //4

                o.Rotation = rotation;

                Protocol.Deserialize(out o.Speed, memAsteroidDesc, ref index);  //4
            }

            return(o);
        }
Example #11
0
        private double DeserializeDouble(StreamBuffer din)
        {
            byte[] obj = this.memDouble;
            double result;

            lock (obj)
            {
                byte[] array = this.memDouble;
                din.Read(array, 0, 8);
                bool isLittleEndian = BitConverter.IsLittleEndian;
                if (isLittleEndian)
                {
                    byte b  = array[0];
                    byte b2 = array[1];
                    byte b3 = array[2];
                    byte b4 = array[3];
                    array[0] = array[7];
                    array[1] = array[6];
                    array[2] = array[5];
                    array[3] = array[4];
                    array[4] = b4;
                    array[5] = b3;
                    array[6] = b2;
                    array[7] = b;
                }
                result = BitConverter.ToDouble(array, 0);
            }
            return(result);
        }
Example #12
0
        private byte[] DeserializeByteArray(StreamBuffer din)
        {
            int num = this.DeserializeInteger(din);

            byte[] array = new byte[num];
            din.Read(array, 0, num);
            return(array);
        }
Example #13
0
 public void EmptyBufferThrowsOnNullBufferRead()
 {
     using (StreamBuffer buffer = new StreamBuffer(0))
     {
         Action action = () => buffer.Read(null, 0, 0);
         action.ShouldThrow <ArgumentNullException>();
     }
 }
Example #14
0
 public void EmptyBufferThrowsOnNegativeCountRead()
 {
     using (StreamBuffer buffer = new StreamBuffer(0))
     {
         Action action = () => buffer.Read(new byte[0], 0, -1);
         action.ShouldThrow <ArgumentOutOfRangeException>();
     }
 }
Example #15
0
    private static object DeserializeChar(StreamBuffer inStream, short Length)
    {
        var bytes = new Byte[1];

        inStream.Read(bytes, 0, 1);

        return((char)bytes[0]);
    }
Example #16
0
 public void EmptyBufferThrowsOnPositiveOffsetRead()
 {
     using (StreamBuffer buffer = new StreamBuffer(0))
     {
         Action action = () => buffer.Read(new byte[0], 1, 0);
         action.ShouldThrow <ArgumentException>();
     }
 }
Example #17
0
            public static object Deserialize(StreamBuffer inStream, short length)
            {
                var wrapper = new PhotonArrayWrapper {
                    Array = new byte[length], Length = length
                };

                inStream.Read(wrapper.Array, 0, length);
                return(wrapper);
            }
Example #18
0
 private int DeserializeInteger(StreamBuffer din)
 {
     byte[] obj = this.memInteger;
     lock (obj)
     {
         byte[] array = this.memInteger;
         din.Read(array, 0, 4);
         return(array[0] << 24 | array[1] << 16 | array[2] << 8 | array[3]);
     }
 }
Example #19
0
 public override short DeserializeShort(StreamBuffer din)
 {
     byte[] obj = this.memShort;
     lock (obj)
     {
         byte[] array = this.memShort;
         din.Read(array, 0, 2);
         return((short)(array[0] << 8 | array[1]));
     }
 }
Example #20
0
 private byte[] DeserializeByteArray(StreamBuffer din, int size = -1)
 {
     if (size == -1)
     {
         size = this.DeserializeInteger(din);
     }
     byte[] array = new byte[size];
     din.Read(array, 0, size);
     return(array);
 }
Example #21
0
    // 受信データからバイト列を読み込んで変換するメソッド
    private static object DeserializeUint(StreamBuffer inStream, short length)
    {
        uint value;
        int  index = 0;

        lock (bufferUint)
        {
            inStream.Read(bufferUint, 0, length);
            MyProtocol.Deserialize(out value, bufferUint, ref index);
        }
        return(value);
    }
Example #22
0
    private static object DeserializeVector3(StreamBuffer inStream, short length)
    {
        var bytes = new byte[3 * 4];

        inStream.Read(bytes, 0, 3 * 4);

        return(new
               Vector3(
                   BitConverter.ToSingle(bytes, 0),
                   BitConverter.ToSingle(bytes, 4),
                   BitConverter.ToSingle(bytes, 8)));
    }
Example #23
0
 public static object Deserialize(StreamBuffer inStream, short length)
 {
     lock (memVector2)
     {
         inStream.Read(memVector2, 0, 4);
         int index = 0;
         int viewId;
         Protocol.Deserialize(out viewId, memVector2, ref index);
         PhotonView view = PhotonView.Find(viewId);
         return(view ? view.GetComponent <Damageable>() : null);
     }
 }
Example #24
0
        private static object DeserializeColor(StreamBuffer inStream, short length)
        {
            Color32 color = new Color32();

            lock (bufferColor) {
                inStream.Read(bufferColor, 0, 4);
                color.r = bufferColor[0];
                color.g = bufferColor[1];
                color.b = bufferColor[2];
                color.a = bufferColor[3];
            }
            return((Color)color);
        }
Example #25
0
 public void AppendTwice()
 {
     using (StreamBuffer buffer = new StreamBuffer(0))
     {
         buffer.Length.Should().Be(0);
         buffer.Write(new byte[] { 0xA, 0xB, 0xC }, 0, 3);
         buffer.Position.Should().Be(3);
         buffer.Length.Should().Be(3);
         buffer.Position = 0;
         byte[] output = new byte[3];
         buffer.Read(output, 0, 3);
         buffer.Position.Should().Be(3);
         output.ShouldAllBeEquivalentTo(new byte[] { 0xA, 0xB, 0xC });
         buffer.Write(new byte[] { 0xD, 0xE, 0xF }, 0, 3);
         buffer.Position.Should().Be(6);
         buffer.Length.Should().Be(6);
         buffer.Position = 0;
         output          = new byte[6];
         buffer.Read(output, 0, 6);
         output.ShouldAllBeEquivalentTo(new byte[] { 0xA, 0xB, 0xC, 0xD, 0xE, 0xF });
     }
 }
Example #26
0
    private static object DeserializeQuaternion(StreamBuffer inStream, short length)
    {
        var bytes = new byte[4 * 4];

        inStream.Read(bytes, 0, 4 * 4);

        return(new
               Quaternion(
                   BitConverter.ToSingle(bytes, 0),
                   BitConverter.ToSingle(bytes, 4),
                   BitConverter.ToSingle(bytes, 8),
                   BitConverter.ToSingle(bytes, 12)));
    }
Example #27
0
            public static object Deserialize(StreamBuffer inBuffer, short length)
            {
                inBuffer.Read(deserializationBuffer, 0, deserializationBuffer.Length);

                int offset = 0;
                int id;

                Protocol.Deserialize(out id, deserializationBuffer, ref offset);
                Debug.Log("Deserializing object of type " + typeof(T).Name + " with id " + id);
                T obj = NetworkableId <T> .FromId(id);

                return(obj);
            }
        private static object DeserializeVector2(StreamBuffer inStream, short length)
        {
            Vector2 vo = new Vector2();
            lock (memVector2)
            {
                inStream.Read(memVector2, 0, 2 * 4);
                int index = 0;
                Protocol.Deserialize(out vo.x, memVector2, ref index);
                Protocol.Deserialize(out vo.y, memVector2, ref index);
            }

            return vo;
        }
Example #29
0
        public override short DeserializeShort(StreamBuffer din)
        {
            byte[] obj = this.memShort;
            short  result;

            lock (obj)
            {
                byte[] array = this.memShort;
                din.Read(array, 0, 2);
                result = (short)((int)array[0] << 8 | (int)array[1]);
            }
            return(result);
        }
Example #30
0
        private int DeserializeInteger(StreamBuffer din)
        {
            byte[] obj = this.memInteger;
            int    result;

            lock (obj)
            {
                byte[] array = this.memInteger;
                din.Read(array, 0, 4);
                result = ((int)array[0] << 24 | (int)array[1] << 16 | (int)array[2] << 8 | (int)array[3]);
            }
            return(result);
        }
Example #31
0
    private static object DeserializeVector3(StreamBuffer inStream, short length)
    {
        Vector3 vo = new Vector3();
        lock (memVector3)
        {
            inStream.Read(memVector3, 0, 3 * 4);
            int index = 0;
            Protocol.Deserialize(out vo.x, memVector3, ref index);
            Protocol.Deserialize(out vo.y, memVector3, ref index);
            Protocol.Deserialize(out vo.z, memVector3, ref index);
        }

        return vo;
    }
Example #32
0
    private static object DeserializePhotonPlayer(StreamBuffer inStream, short length)
    {
        int ID;
        lock (memPlayer)
        {
            inStream.Read(memPlayer, 0, length);
            int off = 0;
            Protocol.Deserialize(out ID, memPlayer, ref off);
        }

        if (PhotonNetwork.networkingPeer.mActors.ContainsKey(ID))
        {
            return PhotonNetwork.networkingPeer.mActors[ID];
        }
        else
        {
            return null;
        }
    }
Example #33
0
    private static object DeserializeQuaternion(StreamBuffer inStream, short length)
    {
        Quaternion o = new Quaternion();

        lock (memQuarternion)
        {
            inStream.Read(memQuarternion, 0, 4 * 4);
            int index = 0;
            Protocol.Deserialize(out o.w, memQuarternion, ref index);
            Protocol.Deserialize(out o.x, memQuarternion, ref index);
            Protocol.Deserialize(out o.y, memQuarternion, ref index);
            Protocol.Deserialize(out o.z, memQuarternion, ref index);
        }

        return o;
    }