示例#1
0
        protected override void InternalSerialize(StreamBuffer buffer)
        {
            base.InternalSerialize(buffer);

            buffer.Write(this.localTime);
            buffer.Write(this.remoteTime);
        }
示例#2
0
    /// <summary>
    /// Serializer for the Line class for PUN 2
    /// </summary>
    /// <param name="outStream"></param>
    /// <param name="customobject"></param>
    /// <returns></returns>
    private static short SerializeLine(StreamBuffer outStream, object customobject)
    {
        Line line = (Line)customobject;

        //Debug.Log("[Serializer] Serializing a line with " + (3 * 4 * line.Points.Count + memLine) + " bytes.");
        byte[] bytes = new byte[3 * 4 * line.Points.Count + memLine];
        int    index = 0;

        for (int i = 0; i < line.Points.Count; i++)
        {
            lock (bytes)
            {
                Protocol.Serialize(line.Points[i].x, bytes, ref index);
                Protocol.Serialize(line.Points[i].y, bytes, ref index);
                Protocol.Serialize(line.Points[i].z, bytes, ref index);
                outStream.Write(bytes, i * 3 * 4, 3 * 4);
            }
        }
        lock (bytes)
        {
            Protocol.Serialize(line.LineID, bytes, ref index);
            outStream.Write(bytes, bytes.Length - (4 * 4) - 4 - 4 - 2, 4);
            Protocol.Serialize(line.m_Color.r, bytes, ref index);
            Protocol.Serialize(line.m_Color.g, bytes, ref index);
            Protocol.Serialize(line.m_Color.b, bytes, ref index);
            Protocol.Serialize(line.m_Color.a, bytes, ref index);
            outStream.Write(bytes, bytes.Length - (4 * 4) - 4 - 2, 4 * 4);
            Protocol.Serialize(line.m_Width, bytes, ref index);
            outStream.Write(bytes, bytes.Length - 4 - 2, 4);
            Protocol.Serialize(line.useRenderer, bytes, ref index);
            outStream.Write(bytes, bytes.Length - 2, 2);
        }
        return((short)(3 * 4 * line.Points.Count + memLine));
    }
示例#3
0
        protected override void InternalSerialize(StreamBuffer buffer)
        {
            base.InternalSerialize(buffer);

            buffer.Write(this.clientTime);
            buffer.Write(this.serverTime);
        }
示例#4
0
        protected override void InternalSerialize(StreamBuffer buffer)
        {
            base.InternalSerialize(buffer);

            buffer.Write(this.count);
            buffer.Write(this.from);
        }
            public override void Write(byte[] buffer, int offset, int count)
            {
                ValidateBufferArguments(buffer, offset, count);
                ThrowIfDisposed();
                ThrowIfWritingNotSupported();

                _buffer.Write(new ReadOnlySpan <byte>(buffer, offset, count));
            }
示例#6
0
        protected override void InternalSerialize(StreamBuffer buffer)
        {
            base.InternalSerialize(buffer);

            buffer.Write(this.result);
            buffer.Write(this.src_cmd);
            buffer.Write(this.src_module);
        }
示例#7
0
        protected override void InternalSerialize(StreamBuffer buffer)
        {
            base.InternalSerialize(buffer);

            buffer.Write(this.ct);
            buffer.WriteUTF8(this.map);
            buffer.WriteUTF8(this.name);
            buffer.Write(this.roomId);
        }
示例#8
0
        /// <summary>
        /// 发送消息到指定的session类型
        /// </summary>
        /// <param name="sessionType">session类型</param>
        /// <param name="data">需要发送的数据</param>
        /// <param name="offset">data的偏移量</param>
        /// <param name="size">data的有用的数据长度</param>
        /// <param name="msgID">消息id</param>
        /// <param name="once">在查询消息类型时是否只对第一个结果生效</param>
        public void SendMsgToSession(SessionType sessionType, byte[] data, int offset, int size, int msgID, bool once = true)
        {
            StreamBuffer sBuffer = StreamBufferPool.Pop();

            sBuffer.Write(size + 2 * sizeof(int));
            sBuffer.Write(msgID);
            sBuffer.Write(data, offset, size);
            byte[] buffer = sBuffer.ToArray();
            StreamBufferPool.Push(sBuffer);
            this.Send(sessionType, buffer, once);
        }
示例#9
0
文件: Packet.cs 项目: niuniuzhu/RC
 protected override void InternalSerialize(StreamBuffer buffer)
 {
     buffer.Write(this.module);
     buffer.Write(this.command);
     buffer.Write(this.pid);
     buffer.Write(this.isRPCReturn);
     if (this.isRPCReturn)
     {
         buffer.Write(this.srcPid);
     }
 }
示例#10
0
        protected override void InternalSerialize(StreamBuffer buffer)
        {
            base.InternalSerialize(buffer);

            buffer.WriteUTF8(this.cid);
            buffer.WriteUTF8(this.name);
            buffer.Write(this.ready);
            buffer.Write(this.skin);
            buffer.Write(this.team);
            buffer.WriteUTF8(this.uid);
        }
		protected override void InternalSerialize( StreamBuffer buffer )
		{
			base.InternalSerialize( buffer );

			buffer.WriteUTF8( this.host );
buffer.WriteUTF8( this.map );
buffer.WriteUTF8( this.name );
int count = this.players.Length;
				buffer.Write( ( ushort )count );
				for ( int i = 0; i < count; ++i )
					this.players[i].Serialize( buffer );
				
buffer.Write( this.roomId );
		}
示例#12
0
        protected override void InternalSerialize(StreamBuffer buffer)
        {
            base.InternalSerialize(buffer);

            int count = this.actions.Length;

            buffer.Write(( ushort )count);
            for (int i = 0; i < count; ++i)
            {
                this.actions[i].Serialize(buffer);
            }

            buffer.Write(this.frameId);
        }
示例#13
0
        /// <summary>
        /// 发送消息到指定session,通常该消息是一条转发消息
        /// </summary>
        /// <param name="sessionType">session类型</param>
        /// <param name="data">需要发送的数据</param>
        /// <param name="offset">data的偏移量</param>
        /// <param name="size">data的有用的数据长度</param>
        /// <param name="msgID">中介端需要处理的消息id</param>
        /// <param name="transID">目标端需要处理的消息id</param>
        /// <param name="gcNet">目标端的网络id</param>
        /// <param name="once">在查询消息类型时是否只对第一个结果生效</param>
        public void TranMsgToSession(SessionType sessionType, byte[] data, int offset, int size, int msgID, int transID, uint gcNet, bool once = true)
        {
            transID = transID == 0 ? msgID : transID;
            StreamBuffer sBuffer = StreamBufferPool.Pop();

            sBuffer.Write(size + 4 * sizeof(int));
            sBuffer.Write(transID);
            sBuffer.Write(msgID);
            sBuffer.Write(gcNet);
            sBuffer.Write(data, offset, size);
            byte[] buffer = sBuffer.ToArray();
            StreamBufferPool.Push(sBuffer);
            this.Send(sessionType, buffer, once);
        }
示例#14
0
            public static short Serialize(StreamBuffer outStream, object customObject)
            {
                var wrapper = (PhotonArrayWrapper)customObject;

                outStream.Write(wrapper.Array, 0, wrapper.Length);
                return((short)wrapper.Length);
            }
示例#15
0
 private void SerializeDouble(StreamBuffer dout, double serObject, bool setType)
 {
     if (setType)
     {
         dout.WriteByte(100);
     }
     byte[] obj = this.memDoubleBlockBytes;
     lock (obj)
     {
         this.memDoubleBlock[0] = serObject;
         Buffer.BlockCopy(this.memDoubleBlock, 0, this.memDoubleBlockBytes, 0, 8);
         byte[] array          = this.memDoubleBlockBytes;
         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;
         }
         dout.Write(array, 0, 8);
     }
 }
示例#16
0
        private bool SerializeCustom(StreamBuffer dout, object serObject)
        {
            CustomType customType = default(CustomType);

            if (Protocol.TypeDict.TryGetValue(serObject.GetType(), out customType))
            {
                if (customType.SerializeStreamFunction == null)
                {
                    byte[] array = customType.SerializeFunction(serObject);
                    dout.WriteByte(99);
                    dout.WriteByte(customType.Code);
                    this.SerializeShort(dout, (short)array.Length, false);
                    dout.Write(array, 0, array.Length);
                    return(true);
                }
                dout.WriteByte(99);
                dout.WriteByte(customType.Code);
                int position = dout.IntPosition;
                dout.IntPosition += 2;
                short num  = customType.SerializeStreamFunction(dout, serObject);
                long  num2 = dout.IntPosition;
                dout.IntPosition = position;
                this.SerializeShort(dout, num, false);
                dout.IntPosition += num;
                if (dout.IntPosition != num2)
                {
                    throw new Exception("Serialization failed. Stream position corrupted. Should be " + num2 + " is now: " + dout.IntPosition + " serializedLength: " + num);
                }
                return(true);
            }
            return(false);
        }
示例#17
0
 public void EmptyBufferCanWriteNothing()
 {
     using (StreamBuffer buffer = new StreamBuffer(0))
     {
         buffer.Write(new byte[0], 0, 0);
     }
 }
示例#18
0
    public static short Serialize(StreamBuffer outstream, object data)
    {
        PlayerInputPacket inputData         = (PlayerInputPacket)data;
        string            inputDataListJson = JsonConvert.SerializeObject(inputData.InputData);


        Encoding encoder = Encoding.UTF8;

        byte[] stringToByte = encoder.GetBytes(inputDataListJson);
        int    stringSize   = stringToByte.Length;


        int byteArrayIndex = 0;

        byte[] obj = new byte[DataSize + stringSize];

        Protocol.Serialize((int)inputData.FrameSent, obj, ref byteArrayIndex);
        Protocol.Serialize((int)inputData.PacketId, obj, ref byteArrayIndex);
        Protocol.Serialize(inputData.PlayerIndex, obj, ref byteArrayIndex);
        Protocol.Serialize(stringSize, obj, ref byteArrayIndex);
        System.Array.Copy(stringToByte, 0, obj, byteArrayIndex, stringToByte.Length);

        outstream.Write(obj, 0, DataSize + stringSize);

        return((short)(stringSize + DataSize));
    }
示例#19
0
 public void EmptyBufferDoesNotThrowOnPositiveOffsetWriteOfNoCharacters()
 {
     using (StreamBuffer buffer = new StreamBuffer(0))
     {
         buffer.Write(new byte[0], 1, 0);
     }
 }
示例#20
0
    public static short PhotonSerialize(StreamBuffer i_OutStream, object i_Customobject)
    {
        tnMultiplayerIndexTable table = (tnMultiplayerIndexTable)i_Customobject;

        int index = 0;

        lock (memTnMultiplayerIndexTable)
        {
            byte[] bytes = memTnMultiplayerIndexTable;
            Protocol.Serialize(table.maxPlayers, bytes, ref index);
            Protocol.Serialize(table.keyCount, bytes, ref index);
            foreach (int key in table.keys)
            {
                List <int> assignedIndices = table.GetAssignedIndicesFor(key);
                Protocol.Serialize(key, bytes, ref index);
                Protocol.Serialize(assignedIndices.Count, bytes, ref index);
                for (int i = 0; i < assignedIndices.Count; ++i)
                {
                    int assignedIndex = assignedIndices[i];
                    Protocol.Serialize(assignedIndex, bytes, ref index);
                }
            }

            i_OutStream.Write(bytes, 0, (4 + (22 * 4) + (22 * 4)));
        }

        return(4 + (22 * 4) + (22 * 4));
    }
示例#21
0
 public void EmptyBufferThrowsOnNullBufferWrite()
 {
     using (StreamBuffer buffer = new StreamBuffer(0))
     {
         Action action = () => buffer.Write(null, 0, 0);
         action.ShouldThrow <ArgumentNullException>();
     }
 }
示例#22
0
        public static void Deserialize(Packet packet, byte[] data, int offset, int size)
        {
            StreamBuffer buffer = BufferPool.Pop();

            buffer.Write(0, data, offset, size);
            packet.Deserialize(buffer);
            BufferPool.Push(buffer);
        }
示例#23
0
 public void EmptyBufferThrowsOnPositiveCountWrite()
 {
     using (StreamBuffer buffer = new StreamBuffer(0))
     {
         Action action = () => buffer.Write(new byte[0], 0, 1);
         action.ShouldThrow <ArgumentException>();
     }
 }
示例#24
0
        private StreamBuffer Init(int start, int count, byte b)
        {
            var streamBuffer = new StreamBuffer(10);

            for (int i = 0; i < start; i++)
            {
                streamBuffer.Write(new byte[] { 0x00 });
            }
            streamBuffer.Seek(start);

            for (int i = 0; i < count; i++)
            {
                streamBuffer.Write(new byte[] { b });
            }

            return(streamBuffer);
        }
示例#25
0
 public void EmptyBufferThrowsOnNegativeOffsetWrite()
 {
     using (StreamBuffer buffer = new StreamBuffer(0))
     {
         Action action = () => buffer.Write(new byte[0], -1, 0);
         action.ShouldThrow <ArgumentOutOfRangeException>();
     }
 }
示例#26
0
        protected override void InternalSerialize(StreamBuffer buffer)
        {
            base.InternalSerialize(buffer);

            buffer.WriteUTF8(this.sender);
            buffer.Write(this.type);
            if (this.type == byte.Parse("1"))
            {
                buffer.Write(this.x);
                buffer.Write(this.y);
                buffer.Write(this.z);
            }

            if (this.type == byte.Parse("2") || this.type == byte.Parse("5"))
            {
                buffer.WriteUTF8(this.target);
            }

            if (this.type == byte.Parse("3"))
            {
                buffer.WriteUTF8(this.sid);
                buffer.WriteUTF8(this.src);
                buffer.WriteUTF8(this.target);
                buffer.Write(this.x);
                buffer.Write(this.y);
                buffer.Write(this.z);
            }

            if (this.type == byte.Parse("4"))
            {
            }
        }
示例#27
0
        public void Serialize(StreamBuffer buffer)
        {
            buffer.Write(this.gcNID);
            int count = this._actions.Count;

            buffer.Write(( byte )count);
            for (int i = 0; i < count; i++)
            {
                Protos.GC2BS_FrameActionInfo info = this._actions[i];
                InputFlag inputFlag = ( InputFlag )info.InputFlag;
                buffer.Write(info.Frame);
                buffer.Write(( byte )inputFlag);
                if ((inputFlag & InputFlag.Move) > 0)
                {
                    buffer.Write(info.V0);
                    buffer.Write(info.V1);
                }

                if ((inputFlag & InputFlag.S1) > 0 ||
                    (inputFlag & InputFlag.S2) > 0)
                {
                    buffer.Write(info.V0);
                }
            }
        }
示例#28
0
        public PacketWriter(StreamBuffer buffer)
        {
            streamBuffer = buffer ?? throw new ArgumentNullException(nameof(buffer));

            Offset     = streamBuffer.WritePosition;
            PacketSize = 0;
            streamBuffer.Write <short>(0);
            writableSize = Math.Min(streamBuffer.WritableSize, ushort.MaxValue);
        }
示例#29
0
 private void SerializeByteArraySegment(StreamBuffer dout, byte[] serObject, int offset, int count, bool setType)
 {
     if (setType)
     {
         dout.WriteByte(120);
     }
     this.SerializeInteger(dout, count, false);
     dout.Write(serObject, offset, count);
 }
示例#30
0
 private void SerializeByteArray(StreamBuffer dout, byte[] serObject, bool setType)
 {
     if (setType)
     {
         dout.WriteByte(120);
     }
     this.SerializeInteger(dout, serObject.Length, false);
     dout.Write(serObject, 0, serObject.Length);
 }
示例#31
0
    private static short SerializeVector2(StreamBuffer outStream, object customobject)
    {
        Vector2 vo = (Vector2)customobject;
        lock (memVector2)
        {
            byte[] bytes = memVector2;
            int index = 0;
            Protocol.Serialize(vo.x, bytes, ref index);
            Protocol.Serialize(vo.y, bytes, ref index);
            outStream.Write(bytes, 0, 2 * 4);
        }

        return 2 * 4;
    }
示例#32
0
    private static short SerializeQuaternion(StreamBuffer outStream, object customobject)
    {
        Quaternion o = (Quaternion)customobject;

        lock (memQuarternion)
        {
            byte[] bytes = memQuarternion;
            int index = 0;
            Protocol.Serialize(o.w, bytes, ref index);
            Protocol.Serialize(o.x, bytes, ref index);
            Protocol.Serialize(o.y, bytes, ref index);
            Protocol.Serialize(o.z, bytes, ref index);
            outStream.Write(bytes, 0, 4 * 4);
        }

        return 4 * 4;
    }
示例#33
0
    private static short SerializePhotonPlayer(StreamBuffer outStream, object customobject)
    {
        int ID = ((PhotonPlayer)customobject).ID;

        lock (memPlayer)
        {
            byte[] bytes = memPlayer;
            int off = 0;
            Protocol.Serialize(ID, bytes, ref off);
            outStream.Write(bytes, 0, 4);
            return 4;
        }
    }