Ejemplo n.º 1
0
        public byte[] SerializePackMsg <T>(T msgbody)
        {
            if (msgbody == null)
            {
                AppModules.Instance.LogManager.Log.Error("Null: msgbody");
                return(null);
            }
            ResetStrem();
            MsgBody = msgbody;

            BinaryWriter br = new BinaryWriter(m_ms);

            if (!MsgHead.SerializeByStream(m_ms))
            {
                AppModules.Instance.LogManager.Log.Error("MsgBase: Serialize");
                return(null);
            }

            ProtoBufUtils.ProtobufSerializeByStream(msgbody, m_ms);
            MsgHead.m_lengh = (uint)m_ms.Length - (uint)MsgHead.Length; //
            MsgHead.SerializeByStreamPos(m_ms, 0);
            //MsgHead.SerializeByStreamPos(m_ms, sizeof(int));//4个字节的长度

            m_ms.Position = 0;


            return(m_ms.ToArray());
        }
Ejemplo n.º 2
0
        public byte[] Serialize <T>(T msgbody)
        {
            if (msgbody == null)
            {
                AppModules.Instance.LogManager.Log.Error("Null: msgbody");
                return(null);
            }
            ResetStrem();
            MsgBody = msgbody;

            if (!MsgHead.SerializeByStream(m_ms))
            {
                AppModules.Instance.LogManager.Log.Error("MsgBase: Serialize");
                return(null);
            }

            ProtoBufUtils.ProtobufSerializeByStream(msgbody, m_ms);
            MsgHead.m_lengh = (uint)m_ms.Length - (uint)MsgHead.Length;
            MsgHead.SerializeByStreamPos(m_ms, 0);
            return(m_ms.ToArray());
        }