Пример #1
0
        private static void Test3()
        {
            UnityEngine.Debug.Log("optional 序列化测试");

            //message login_req
            //{
            //	required string account = 1;
            //	required string password = 2;
            //	optional bool isdetail = 3;
            //	optional string userid = 4;
            //	optional string usersession = 5;
            //	optional EAuthType loginType = 6;
            //}

            SProtoSpace.login_req role = new SProtoSpace.login_req();
            UnityEngine.Debug.Log(role.account);
            role.password = "******";
            UnityEngine.Debug.Log(role.password);
            role.isdetail = true;
            UnityEngine.Debug.Log(role.hasIsdetail);


            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            role.writeTo(ms);

            byte[] bytes = ms.ToArray();

            UnityEngine.Debug.Log(role.printByte(bytes));

            ms.Dispose();

            SProtoSpace.login_req role2 = new SProtoSpace.login_req();
            role2.mergeFrom(new System.IO.MemoryStream(bytes));
            UnityEngine.Debug.Log("反序列化:" + role2.hasIsdetail);
            UnityEngine.Debug.Log("反序列化:" + role2.password);


            UnityEngine.Debug.Log("======");
        }
Пример #2
0
        private static void Test4()
        {
            UnityEngine.Debug.Log("枚举 序列化测试");


            SProtoSpace.login_req role = new SProtoSpace.login_req();
            UnityEngine.Debug.Log(role.account);
            role.password = "******";
            UnityEngine.Debug.Log(role.password);
            UnityEngine.Debug.Log(role.testEnum);

            role.testEnum = SProtoSpace.protoId.login_need_queued_ntf_id;

            role.isdetail  = true;
            role.loginType = SProtoSpace.EAuthType.AUTH_XIAOMI;
            UnityEngine.Debug.Log(role.hasIsdetail);


            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            role.writeTo(ms);

            byte[] bytes = ms.ToArray();

            UnityEngine.Debug.Log(role.printByte(bytes));

            ms.Dispose();

            SProtoSpace.login_req role2 = new SProtoSpace.login_req();
            role2.mergeFrom(new System.IO.MemoryStream(bytes));
            UnityEngine.Debug.Log("反序列化:" + role2.hasIsdetail);
            UnityEngine.Debug.Log("反序列化:" + role2.password);
            UnityEngine.Debug.Log("反序列化:" + role2.loginType);
            UnityEngine.Debug.Log("反序列化:" + role2.testEnum);

            UnityEngine.Debug.Log("======");
        }