Ejemplo n.º 1
0
        public void TestCompact()
        {
            var v = new SampleRect {
                A = new SamplePoint { X = 33, Y = 44 },
                B = new SamplePoint { X = 55, Y = 66 },
            };
            var js = new JsonSerializer();
            js.JsonOptions.Indent = "";
            js.JsonOptions.FieldSeparator = " ";
            var result = js.ToString(v);
            Assert.AreEqual("{ \"A\":[ 33, 44 ], \"B\":[ 55, 66 ] }", result);

            var jd = new JsonDeserializer();
            var w = new SampleRect();
            jd.FromString(w, result);
            CheckSampleRect(v, w);

            w = (SampleRect)SampleRect_JsonDeserializer.Instance.FromString(result);
            CheckSampleRect(v, w);
        }
Ejemplo n.º 2
0
        public void TestStruct()
        {
            var v = new SampleRect {
                A = new SamplePoint { X = 33, Y = 44 },
                B = new SamplePoint { X = 55, Y = 66 },
            };
            var js = new JsonSerializer();
            js.JsonOptions.Indent = "";
            js.JsonOptions.FieldSeparator = " ";
            js.JsonOptions.IgnoreCompact = true;
            var result = js.ToString(v);
            Assert.AreEqual("{ \"A\":{ \"X\":33, \"Y\":44 }, \"B\":{ \"X\":55, \"Y\":66 } }", result);

            var jd = new JsonDeserializer();
            var w = new SampleRect();
            jd.FromString(w, result);
            CheckSampleRect(v, w);

            w = (SampleRect)SampleRect_JsonDeserializer.Instance.FromString(result);
            CheckSampleRect(v, w);

            var jdg = new JsonDeserializerGenerator();
            jdg.Assembly = GetType().Assembly;
            var p = (SamplePoint)jdg.FromString(new SamplePoint(), "{ \"X\":34, \"Y\":45 }");
            Assert.AreEqual(34, p.X);
            Assert.AreEqual(45, p.Y);
        }
Ejemplo n.º 3
0
 private void CheckSampleRect(SampleRect expected, SampleRect actual)
 {
     Assert.AreEqual(expected.A.X, actual.A.X);
     Assert.AreEqual(expected.A.Y, actual.A.Y);
     Assert.AreEqual(expected.B.X, actual.B.X);
     Assert.AreEqual(expected.B.Y, actual.B.Y);
 }
Ejemplo n.º 4
0
        public void TestStruct()
        {
            var v = new SampleRect {
                A = new SamplePoint { X = 33, Y = 44 },
                B = new SamplePoint { X = 55, Y = 66 },
            };
            var bs = new BinarySerializer();
            var result = bs.ToBytes(v);
            Assert.AreEqual(
                "20 01 00 " + XS(typeof(SampleRect)) + " 02 00 " +
                XS("A", RoughType.Record, "B", RoughType.Record) +
            " 01 00 02 00 " + XS(typeof(SamplePoint)) + " 02 00 " +
            XS("X", RoughType.Int, "Y", RoughType.Int) +
            " 21 00 00 00 2C 00 00 00 " +
            "02 00 02 00 37 00 00 00 42 00 00 00 00 00",
            XS(result));

            var bd = new BinaryDeserializer();
            var w = new SampleRect();
            bd.FromBytes(w, result);
            CheckSampleRect(v, w);

            var bdg = new BinaryDeserializerGen();
            w = (SampleRect)bdg.FromBytes(result);
            CheckSampleRect(v, w);

            var p = (SamplePoint)bdg.FromBytes(new SamplePoint(), SX("20 02 00 22 00 00 00 2D 00 00 00"));
            Assert.AreEqual(34, p.X);
            Assert.AreEqual(45, p.Y);
        }