public DGPKG doDeserialize(byte[] data) { if (m_assembly == null) { return(null); } System.IO.MemoryStream stream = new System.IO.MemoryStream(data, 0, sizeof(uint) * 2); System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(stream); m_totalLength = binaryReader.ReadUInt32(); m_headerLength = binaryReader.ReadUInt32(); int offset = sizeof(uint) * 2; System.IO.MemoryStream streamHeader = new System.IO.MemoryStream(data, offset, (int)m_headerLength); ProtoRW rw = new ProtoRW(); m_header = rw.Deserialize(streamHeader, null, typeof(Header)) as Header;//ProtoBuf.Serializer.Deserialize<Header>(streamHeader); offset += (int)m_headerLength; System.IO.MemoryStream streamBody = new System.IO.MemoryStream(data, offset, (int)m_totalLength - offset); string msg_full_name = m_header.msg_full_name; //UnityEngine.Debug.LogError(msg_full_name); //UnityEngine.Debug.LogError(m_assembly.GetType(m_header.msg_full_name)); //UnityEngine.Debug.LogError(new CS.ShardLoginRsp().GetType()); //UnityEngine.Debug.LogError(typeof(CS.ShardLoginRsp)); m_body = rw.Deserialize(streamBody, null, m_assembly.GetType(m_header.msg_full_name));//ProtoBuf.Meta.RuntimeTypeModel.Default.Deserialize(streamBody, null, Type.GetType(m_header.msg_full_name)); //wl_res.AIConfig aiconfig = new wl_res.AIConfig(); return(this); }
public byte[] doSerialize() { if (m_assembly == null) { return(null); } m_header.msg_full_name = m_body.ToString(); System.IO.MemoryStream stream = new System.IO.MemoryStream(); stream.Position = sizeof(uint) * 2; ProtoRW rw = new ProtoRW(); //ProtoBuf.Serializer.Serialize(stream, m_header); rw.Serialize(stream, m_header); m_headerLength = (uint)(stream.Length - sizeof(uint) * 2); //ProtoBuf.Serializer.Serialize(stream, m_body); rw.Serialize(stream, m_body); System.IO.BinaryWriter binaryWriter = new System.IO.BinaryWriter(stream); stream.Position = 0; m_totalLength = (uint)stream.Length; binaryWriter.Write(m_totalLength); binaryWriter.Write(m_headerLength); binaryWriter.Flush(); return(stream.ToArray()); }