Exemplo n.º 1
0
    public byte[] ToArray(MMO_MemoryStream ms, bool isChild = false)
    {
        ms.SetLength(0);
        if (!isChild)
        {
            ms.WriteUShort(ProtoCode);
        }

        ms.WriteInt(RoleType);

        byte[] buff_CurrRole = CurrRole.ToArray(new MMO_MemoryStream(), true);
        ms.WriteInt(buff_CurrRole.Length);
        ms.Write(buff_CurrRole, 0, buff_CurrRole.Length);

        if (RoleList != null)
        {
            int len_RoleList = RoleList.Count;
            ms.WriteInt(len_RoleList);
            for (int i = 0; i < len_RoleList; i++)
            {
                Role_DataProto _Role_DataProto = RoleList[i];
                byte[]         _buff_Curr      = _Role_DataProto.ToArray(new MMO_MemoryStream(), true);
                ms.WriteInt(_buff_Curr.Length);
                ms.Write(_buff_Curr, 0, _buff_Curr.Length);
            }
        }
        else
        {
            ms.WriteInt(0);
        }

        return(ms.ToArray());
    }
Exemplo n.º 2
0
    public byte[] ToArray(bool isChild = false)
    {
        MMO_MemoryStream ms = null;

        if (!isChild)
        {
            ms = GameEntry.Socket.SocketSendMS;
            ms.SetLength(0);
            ms.WriteUShort(ProtoCode);
        }
        else
        {
            ms = GameEntry.Pool.DequeueClassObject <MMO_MemoryStream>();
            ms.SetLength(0);
        }

        ms.WriteInt(RoleType);

        byte[] buff_CurrRole = CurrRole.ToArray(true);
        ms.WriteInt(buff_CurrRole.Length);
        ms.Write(buff_CurrRole, 0, buff_CurrRole.Length);

        if (RoleList != null)
        {
            int len_RoleList = RoleList.Count;
            ms.WriteInt(len_RoleList);
            for (int i = 0; i < len_RoleList; i++)
            {
                Role_DataProto _Role_DataProto = RoleList[i];
                byte[]         _buff_Curr      = _Role_DataProto.ToArray(true);
                ms.WriteInt(_buff_Curr.Length);
                ms.Write(_buff_Curr, 0, _buff_Curr.Length);
            }
        }
        else
        {
            ms.WriteInt(0);
        }

        byte[] retBuffer = ms.ToArray();
        if (isChild)
        {
            GameEntry.Pool.EnqueueClassObject(ms);
        }
        return(retBuffer);
    }