示例#1
0
        public override void Run()
        {
            // create some info
            var userInfo = new UserInformation
            {
                UserName       = "******",
                FavoriteNumber = 1337,
            };

            // print it to the screen
            Console.WriteLine($"My {nameof(UserInformation)}:");
            userInfo.Print();

            // we will serialize it into an object[] here
            var data = DConverter <UserInformation> .Serialize(userInfo);

            Console.WriteLine($"Serialized {nameof(UserInformation)}:");
            data.PrintContents();

            // deserialize the data
            // guarenteed to be true since we didn't fiddle with data
            var success = DConverter <UserInformation> .TryDeserialize(data, out var deserializedUserInfo);

            Console.WriteLine($"Able to deserialize {nameof(data)}: {success}");

            if (success)
            {
                Console.WriteLine($"Deserialized user information:");

                // print out our new information.
                deserializedUserInfo.Print();
            }
        }
示例#2
0
        public override void Run()
        {
            User myUser = new User
            {
                Username = "******",
                Id       = 1337,
                Money    = 1_000_000,
            };

            object[] serializedUser = DConverter <User> .Serialize(myUser);

            Console.WriteLine(JsonConvert.SerializeObject(serializedUser));
            // outputs:
            // ["SirJosh3917",1337,1000000]

            object[] userData = new object[] { "Jeremy", 63, 1_000 };

            if (DConverter <User> .TryDeserialize(userData, out User deserializedUser))
            {
                // this gets evaluated

                Console.WriteLine(JsonConvert.SerializeObject(deserializedUser));
                // outputs:
                // {"Username":"******","Id":63,"Money":1000}
            }
        }
示例#3
0
        public override void Run()
        {
            var messageData = new object[][] {
                // Optional fields *must* have some kind of data to them - it can be anything, as long as it exists
                // e.g. 'null', or an integer (in case of h4x0r)

                // they'll be their default values if it's unable to deserialize it, but it being unable to deserialize
                // won't affect anything.
                new object[] { "SirJosh3917", "Hello all! I am the owner of this server!", true },
                new object[] { "Peasant", "I am a lonely citizen :(", false },
                new object[] { "h4x0r", "aM hAcKuR tRyNa RuIn YeR sTuFf", 1337 },
            };

            foreach (var i in messageData)
            {
                if (!DConverter <Message> .TryDeserialize(i, out var message))
                {
                    // TODO: throw ThisShouldntHappenException()
                    Console.WriteLine("Uh-oh! The example failed D:");
                }

                Console.WriteLine("Message data:");
                i.PrintContents();

                Console.WriteLine("Deserialized data:");
                message.Print();
            }
        }
示例#4
0
        public ILPerformance()
        {
            var c = new Compiler <Test>();

            var modules = c.Compile((i) =>
            {
                return(new Container(new Member((PropertyInfo)i)));
            });

            _ilDes = c.CompileILDeserialize(modules);
            _ilSer = c.CompileILSerialize(modules);

            _class = new Test
            {
                StringA = "a"
            };

            _data = DConverter <Test> .Serialize(_class);

            foreach (var benchmark in GetType()
                     .GetMethods()
                     .Where(x => x.GetCustomAttributes(true)
                            .OfType <BenchmarkAttribute>()
                            .Count() > 0))
            {
                benchmark.Invoke(this, null);
            }
        }
        public TestClass DConverterDecoratorDeserialize()
        {
            if (DConverter <TestClass> .TryDeserialize(_data, out var result))
            {
                return(result);
            }

            throw new ShouldNotHappenException();
        }
示例#6
0
        public Test DConverterDeserialize()
        {
            if (!DConverter <Test> .TryDeserialize(_data, out var result))
            {
                throw new Exception();
            }

            return(result);
        }
        public Benchmarks()
        {
            _testClass = new TestClass
            {
                String       = "Hello, World!",
                Int          = 1234,
                SomeIntegers = new[]
                {
                    1, 2, 8, 9, 20, 15
                },
                LongInt          = 1106300L,
                UltraLongInt     = 11063002uL,
                Identifier       = 0xFF,
                SuperUselessByte = 0x0A,
            };

            _data = DConverter <TestClass> .Serialize(_testClass);

            _pm = new ProtocolMessage.ProtocolMessageManager();

            if (!(new ConverterContainer().RequestConverter <TestClass>() is ILConverter <TestClass> ilConv))
            {
                throw new Exception($"IL is not fully spported for the benchmarks yet.");
            }

            _tc = ilConv;

            foreach (var benchmark in GetType()
                     .GetMethods()
                     .Where(x => x.GetCustomAttributes(true)
                            .OfType <BenchmarkAttribute>()
                            .Count() > 0))
            {
                benchmark.Invoke(this, null);
            }
        }
 public object[] DecoratorSerialize()
 => DConverter <TestClass> .Serialize(_testClass);
示例#9
0
 public object[] DConverterSerialize()
 {
     return(DConverter <Test> .Serialize(_class));
 }