示例#1
0
    public override void Deserialize(byte[] data)
    {
        MyByteBuffer bf = new MyByteBuffer(data.Length, false);

        bf.put(data);
        framID        = bf.readInt64();
        actorServerID = bf.readInt32();
        dir           = new Int3(bf.readInt32(), bf.readInt32(), bf.readInt32());
        speed         = bf.readInt32();
    }
示例#2
0
    private void onReceive(byte[] bytes, int len)
    {
        try
        {
            if (len > 0 && bytes != null)
            {
                if (len > mByteBuffer.canUse())
                {
                    MyByteBuffer byteBuffer = new MyByteBuffer(mByteBuffer.maxSize() * 2 + len, false);
                    byteBuffer.copyFrom(mByteBuffer);
                    mByteBuffer = byteBuffer;
                }

                mByteBuffer.put(bytes, len);

                do
                {
                    if (mByteBuffer.remaining() < 4)
                    {
                        break;
                    }

                    int tmp    = mByteBuffer.readInt32();
                    int bufLen = (tmp & 0x7FFFFF);
                    if (bufLen > mByteBuffer.maxSize() || bufLen <= 0)
                    {
                        Debug.LogError("数据长度超过限制: " + bufLen);
                        break;
                    }

                    if (mByteBuffer.remaining() < bufLen)
                    {
                        mByteBuffer.resetHead(4);
                        //Log(EventId.Net_Error, "remaining 长度不够:" + bufLen);
                        break;
                    }

                    int msgID = mByteBuffer.readInt32();

                    //
                    byte[] content = null;
                    if (bufLen - 4 > 0)
                    {
                        content = new byte[bufLen - 4];
                        mByteBuffer.readBytes(content);
                    }

                    lock (lockObj)
                    {
                        msgQueue.Enqueue(new MessageData {
                            msgID = msgID, data = content
                        });
                    }

                    // Logger.err("收到服务器数据:" + BitConverter.ToInt32(content, 0));

                    //////////MessageUtils.sendToGameLogic(msgId, content);
                }while (true);
            }
        }
        catch (Exception ex)
        {
            Logger.err(ex.ToString());
        }
    }
示例#3
0
    public virtual void Deserialize(byte[] data)
    {
        MyByteBuffer bf = new MyByteBuffer(data.Length, false);

        bf.put(data);
    }