Beispiel #1
0
        public void SmallIntVectorAndNestedVector()
        {
            var bytes = FlexBufferBuilder.Vector(v1 =>
            {
                v1.Add(1);
                v1.Add(2);
                v1.Add(3);
                v1.Add(4);
                v1.Add(5);
                v1.Vector(v2 => {
                    v2.Add("hello");
                    v2.Add("world");
                });
            });

            var flx = FlxValue.FromBytes(bytes);

            Assert.AreEqual(6, flx.AsVector.Length);
            Assert.AreEqual(1, flx[0].AsLong);
            Assert.AreEqual(2, flx[1].AsLong);
            Assert.AreEqual(3, flx[2].AsLong);
            Assert.AreEqual(4, flx[3].AsLong);
            Assert.AreEqual(5, flx[4].AsLong);
            Assert.AreEqual(2, flx[5].AsVector.Length);
            Assert.AreEqual("hello", flx[5][0].AsString);
            Assert.AreEqual("world", flx[5][1].AsString);
        }
Beispiel #2
0
        public void IndirectValuesInVectorToJson()
        {
            var bytes = FlexBufferBuilder.Vector(root =>
            {
                root.Add(-123, true);
                root.Add(123UL, true);
                root.Add(123.3, true);
            });

            var flx = FlxValue.FromBytes(bytes);

            Assert.AreEqual(
                "[-123,123,123.3]",
                flx.ToJson);
        }
Beispiel #3
0
        public void IndirectValuesInVector()
        {
            var bytes = FlexBufferBuilder.Vector(root =>
            {
                root.Add(-123, true);
                root.Add(123UL, true);
                root.Add(123.3, true);
            });

            var flx = FlxValue.FromBytes(bytes);

            Assert.AreEqual(3, flx.AsVector.Length);
            Assert.AreEqual(-123, flx[0].AsLong);
            Assert.AreEqual(123, flx[1].AsULong);
            Assert.AreEqual(123.3, flx[2].AsDouble);
        }
Beispiel #4
0
        public void AddNullAndBlobToNestedToJson()
        {
            var bytes = FlexBufferBuilder.Vector(root =>
            {
                root.AddNull();
                root.Add(new byte[] { 1, 2, 3 });
                root.Map(map =>
                {
                    map.AddNull("a");
                    map.Add("b", new byte[] { 3, 4, 5 });
                });
            });

            var flx = FlxValue.FromBytes(bytes);

            Assert.AreEqual(
                "[null,\"AQID\",{\"a\":null,\"b\":\"AwQF\"}]",
                flx.ToJson);
        }
Beispiel #5
0
        public void SmallIntVector()
        {
            var bytes = FlexBufferBuilder.Vector(builder =>
            {
                builder.Add(1);
                builder.Add(2);
                builder.Add(3);
                builder.Add(4);
                builder.Add(5);
            });

            var flx = FlxValue.FromBytes(bytes);

            Assert.AreEqual(5, flx.AsVector.Length);
            Assert.AreEqual(1, flx[0].AsLong);
            Assert.AreEqual(2, flx[1].AsLong);
            Assert.AreEqual(3, flx[2].AsLong);
            Assert.AreEqual(4, flx[3].AsLong);
            Assert.AreEqual(5, flx[4].AsLong);
        }