public void SavingComplexObject()
    {
        MyComplexObject[] MySaveItem = new MyComplexObject[1000];
        for (int i = 0; i < MySaveItem.Length; i++)
        {
            var item = new MyComplexObject();
            item.myPosition        = Vector3.one * i;
            item.myPositionHistory = new Vector3[100];
            item.myChatHistory     = new string[100];
            for (int j = 0; j < 100; j++)
            {
                item.myPositionHistory[j] = Vector3.one * j;
                item.myChatHistory[j]     = "Chat line: " + j;
            }
        }
        var mySaveObject = ObjectToByteArray(MySaveItem);

        byte[] compressed    = CLZF2.Compress(mySaveObject);
        byte[] decompressed  = CLZF2.Decompress(compressed);
        var    outSaveObject = ObjectToByteArray <MyComplexObject[]>(decompressed);

        Assert.AreEqual(mySaveObject.Length, decompressed.Length);
        Assert.AreEqual(mySaveObject, decompressed);
        Assert.AreEqual(outSaveObject, MySaveItem);
    }
Beispiel #2
0
    public static MyComplexObject ReadComplexObject(this BinaryReader br)
    {
        var o = new MyComplexObject();

        o.Field1 = br.ReadString();
        return(o);
    }
Beispiel #3
0
        public void ShouldInclude_ByPropertyList()
        {
            var object1 = new MyComplexObject(1, "A string", new Location(49.282730, -123.120735));
            var object2 = new MyComplexObject(1, "A different string", new Location(40.712776, -123.120735));

            var diff = object1.Diff(object2, ComparisonOptions.IncludeList | ComparisonOptions.All, x => x.Id);

            Assert.AreEqual(0, diff.Count);
        }
Beispiel #4
0
        public void ShouldExclude_ByPropertyPathList()
        {
            var object1 = new MyComplexObject(1, "A string", new Location(49.282730, -123.120735));
            var object2 = new MyComplexObject(1, "A different string", new Location(40.712776, -123.120735));

            var diff = object1.Diff(object2, ".Name", ".Location.Latitude");

            Assert.AreEqual(0, diff.Count);
        }
Beispiel #5
0
        public void ShouldExclude_ByPropertyNameList()
        {
            var object1 = new MyComplexObject(1, "A string", true);
            var object2 = new MyComplexObject(1, "A different string", true);

            var diff = object1.Diff(object2, propertiesToExcludeOrInclude: "Name");

            Assert.AreEqual(0, diff.Count);
        }
        public void Hirarchical_Integration_test()
        {
            MyComplexObject testObj = new MyComplexObject()
            {
                Name         = "Root",
                Value        = 1,
                runtimeThing = 30,// should not be preserved
                ArrayOfInts  = new int[] { 1, 2, 3, 4 },
                ChildObject  = new MyComplexObject()
                {
                    Name               = "branch",
                    Value              = 3,
                    ArrayOfInts        = new int[] { 999, 200 },
                    ArrayOfChildObject = new MyComplexObject[] {
                        new MyComplexObject()
                        {
                            Name = "1st ArrayItem"
                        },
                        new MyComplexObject()
                        {
                            Name = "2nd ArrayItem"
                        },
                        new MyComplexObject()
                        {
                            Name = "3rd ArrayItem, with more than 31 chars (extra byte needed)"
                        },
                        null,
                        new MyComplexObject()
                        {
                            Name = "5th ArrayItem, with a string that takes more than 255 bytes so we need two bytes to contain the length of this nice and lengthy example, and we are not there yet... well it is a little chatty example I must admit, but we'll get there eventually, maybe, Yes!"
                        },
                    }
                },
                Date = new DateTime(2021, 3, 5, 11, 32, 20),
                NullableTypeWithValue = 3
            };

            byte[] buffer = MsgPackSerializer.Serialize(testObj);

            MyComplexObject ret = MsgPackSerializer.Deserialize <MyComplexObject>(buffer);

            Assert.AreEqual(testObj.Name, ret.Name);
            Assert.AreEqual(testObj.Value, ret.Value);
            Assert.AreNotEqual(testObj.runtimeThing, ret.runtimeThing);

            Assert.AreEqual(testObj.ChildObject.Name, ret.ChildObject.Name);
            Assert.AreEqual(testObj.ChildObject.ArrayOfChildObject[2].Name, ret.ChildObject.ArrayOfChildObject[2].Name);
            Assert.AreEqual(testObj.ChildObject.ArrayOfChildObject[3], ret.ChildObject.ArrayOfChildObject[3]);
            Assert.AreEqual(testObj.ChildObject.ArrayOfChildObject[4].Name, ret.ChildObject.ArrayOfChildObject[4].Name);
            Assert.AreEqual(testObj.NullableType, ret.NullableType);
            Assert.AreEqual(testObj.NullableTypeWithValue, ret.NullableTypeWithValue);
            Assert.AreEqual(testObj.Date, ret.Date);
        }