diff --git a/xiaofang/Assets/comm/Proto/ProtoBufffer.cs b/xiaofang/Assets/comm/Proto/ProtoBufffer.cs new file mode 100644 index 00000000..46b1d5a6 --- /dev/null +++ b/xiaofang/Assets/comm/Proto/ProtoBufffer.cs @@ -0,0 +1,28 @@ +using Google.Protobuf; +using System; +public class ProtoBufffer +{ + public static byte[] Serialize(IMessage message) + { + return message.ToByteArray(); + } + + public static T DeSerialize(byte[] packet) where T : IMessage, new() + { + IMessage message = new T(); + try + { + return (T)message.Descriptor.Parser.ParseFrom(packet); + } + catch (System.Exception e) + { + throw; + } + } + + internal static T DeSerialize(ByteString data) + { + throw new NotImplementedException(); + } +} + diff --git a/xiaofang/Assets/comm/Proto/ProtoBufffer.cs.meta b/xiaofang/Assets/comm/Proto/ProtoBufffer.cs.meta new file mode 100644 index 00000000..889e6023 --- /dev/null +++ b/xiaofang/Assets/comm/Proto/ProtoBufffer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cbf21bdbee5a320489df7092ce24d9a7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/xiaofang/Assets/comm/test.cs b/xiaofang/Assets/comm/test.cs index 39114758..3c173385 100644 --- a/xiaofang/Assets/comm/test.cs +++ b/xiaofang/Assets/comm/test.cs @@ -300,7 +300,7 @@ public class test : MonoBehaviour case "hall.BroadcastMessage": UserJoinResponse userJoinResponse = ProtoBufffer.DeSerialize(bytes); Debug.Log("玩家昵称:" + userJoinResponse.NickName + ",房间:" + userJoinResponse.RoomId.ToString() + ",用户角色"+ userJoinResponse.RoleName); - userJoinResponse. + break; //