Ejemplo n.º 1
0
        static void NetworkTest()
        {
            var config = new SerializerConfig();

            config.Advanced.PersistTypeCache = true;
            config.KnownTypes.Add(typeof(SetName));
            config.KnownTypes.Add(typeof(NewPlayer));
            config.KnownTypes.Add(typeof(LongEnum));
            config.KnownTypes.Add(typeof(ByteEnum));
            config.KnownTypes.Add(typeof(ComplexClass));
            config.KnownTypes.Add(typeof(Complex2));

            var msg = new SetName
            {
                Name = "abc",
                Type = SetName.SetNameType.Join
            };

            CerasSerializer sender   = new CerasSerializer(config);
            CerasSerializer receiver = new CerasSerializer(config);

            Console.WriteLine("Hash: " + sender.ProtocolChecksum.Checksum);

            var data = sender.Serialize <object>(msg);

            PrintData(data);
            data = sender.Serialize <object>(msg);
            PrintData(data);

            var obj   = receiver.Deserialize <object>(data);
            var clone = (SetName)obj;

            Debug.Assert(clone.Name == msg.Name);
            Debug.Assert(clone.Type == msg.Type);
        }
Ejemplo n.º 2
0
        public ComplexClass()
        {
            Num = rng.Next(0, 10);
            if (Num < 8)
            {
                RefA = new ComplexClass();

                var c2 = new Complex2 {
                    Parent = this
                };
                c2.Self = c2;
                RefB    = c2;

                SetName = new SetName {
                    Type = SetName.SetNameType.Change, Name = "asd"
                };
            }
        }