public void ComplexMap() { var value = new Dictionary <string, dynamic>() { { "age", 35 }, { "flags", new[] { true, false, true, true } }, { "weight", 72.5 }, { "name", "Maxim" }, { "address", new Dictionary <string, dynamic>() { { "city", "Bla" }, { "zip", "12345" }, { "countryCode", "XX" }, } }, }; var bytes = FlexBuffer.From(value); var flx = FlxValue.FromBytes(bytes); Assert.AreEqual(value.Count, flx.AsMap.Length); Assert.AreEqual(35, flx["age"].AsLong); Assert.AreEqual(72.5, flx["weight"].AsDouble); Assert.AreEqual("Maxim", flx["name"].AsString); Assert.AreEqual(4, flx["flags"].AsVector.Length); Assert.AreEqual(true, flx["flags"][0].AsBool); Assert.AreEqual(false, flx["flags"][1].AsBool); Assert.AreEqual(true, flx["flags"][2].AsBool); Assert.AreEqual(true, flx["flags"][3].AsBool); Assert.AreEqual(3, flx["address"].AsMap.Length); Assert.AreEqual("Bla", flx["address"]["city"].AsString); Assert.AreEqual("12345", flx["address"]["zip"].AsString); Assert.AreEqual("XX", flx["address"]["countryCode"].AsString); }
public void LongStringArray() { var s1 = new StringBuilder(); for (int i = 0; i < 260; i++) { s1.Append("a"); } var s2 = new StringBuilder(); for (int i = 0; i < 260000; i++) { s2.Append("b"); } var list = new List <string>(2) { s1.ToString(), s2.ToString() }; var bytes = FlexBuffer.From(list); var flx = FlxValue.FromBytes(bytes); Assert.AreEqual(2, flx.AsVector.Length); Assert.AreEqual(s1.ToString(), flx[0].AsString); Assert.AreEqual(s2.ToString(), flx[1].AsString); }
public void TestPrettyJsonMap() { var dict = new Dictionary <string, object>() { { "a", 1 }, { "b", 2 }, { "c", 3 }, { "d", new [] { 1, 2, 3 } } }; var expected = @"{ ""a"" : 1, ""b"" : 2, ""c"" : 3, ""d"" : [ 1, 2, 3 ] }".Replace("\r", ""); var bytes = FlexBuffer.From(dict); var flx = FlxValue.FromBytes(bytes); Assert.AreEqual(expected, flx.ToPrettyJson()); }
public void IntVector() { Check(new byte[] { 3, 1, 2, 3, 3, 44, 1 }, FlexBuffer.From(new [] { 1, 2, 3 })); Check(new byte[] { 3, 255, 2, 3, 3, 44, 1 }, FlexBuffer.From(new [] { -1, 2, 3 })); Check(new byte[] { 3, 0, 1, 0, 43, 2, 3, 0, 6, 45, 1 }, FlexBuffer.From(new [] { 1, 555, 3 })); Check(new byte[] { 3, 0, 0, 0, 1, 0, 0, 0, 204, 216, 0, 0, 3, 0, 0, 0, 12, 46, 1 }, FlexBuffer.From(new [] { 1, 55500, 3 })); Check(new byte[] { 3, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 172, 128, 94, 239, 12, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 24, 47, 1 }, FlexBuffer.From(new [] { 1, 55555555500, 3 })); }
public void StringIntDictSingleValue() { var dict = new Dictionary <string, int>() { { "a", 12 } }; Check( new byte[] { 97, 0, 1, 3, 1, 1, 1, 12, 4, 2, 36, 1 }, FlexBuffer.From(dict)); }
public void StringIntDict() { var dict = new Dictionary <string, int>() { { "", 45 }, { "a", 12 } }; Check( new byte[] { 0, 97, 0, 2, 4, 4, 2, 1, 2, 45, 12, 4, 4, 4, 36, 1 }, FlexBuffer.From(dict)); }
public void IntArray() { var value = new[] { 1, 2, 3, -1 }; var bytes = FlexBuffer.From(value); var flx = FlxValue.FromBytes(bytes); Assert.AreEqual(value.Length, flx.AsVector.Length); for (var i = 0; i < value.Length; i++) { Assert.AreEqual(value[i], flx[i].AsLong, $"Not equal at index {i}"); } }
public void MixedVectorWithVectorAndInt() { var value = new List <object>() { new [] { 61 }, 64 }; // Swift has {1, 61, 4, 2, 3, 64, 40, 4, 4, 40, 1} but it is also untyped Check( new byte[] { 1, 61, 2, 2, 64, 44, 4, 4, 40, 1 }, FlexBuffer.From(value)); }
public void BoolArray() { var value = new[] { true, false, true, true }; var bytes = FlexBuffer.From(value); var flx = FlxValue.FromBytes(bytes); Assert.AreEqual(value.Length, flx.AsVector.Length); for (var i = 0; i < value.Length; i++) { var v = flx[i].AsBool; Assert.AreEqual(value[i], v, $"Not equal at index {i}"); } }
public void StringArray() { var value = new[] { "Max", "Maxim", "Alex", "Hi 😂🤣😍🤪" }; var bytes = FlexBuffer.From(value); var flx = FlxValue.FromBytes(bytes); Assert.AreEqual(value.Length, flx.AsVector.Length); for (var i = 0; i < value.Length; i++) { var v = flx[i].AsString; Assert.AreEqual(value[i], v, $"Not equal at index {i}"); } }
public void SimpleMap() { var value = new Dictionary <string, int>() { { "a", 12 }, { "b", 45 } }; var bytes = FlexBuffer.From(value); var flx = FlxValue.FromBytes(bytes); Assert.AreEqual(value.Count, flx.AsMap.Length); Assert.AreEqual(value["a"], flx["a"].AsLong); Assert.AreEqual(value["b"], flx["b"].AsLong); }
public void IterateOverVector() { var ints = new[] { 1, 2, 3 }; var bytes = FlexBuffer.From(ints); var flx = FlxValue.FromBytes(bytes); var i = 0; foreach (var value in flx.AsVector) { Assert.AreEqual(ints[i], value.AsLong); i++; } Assert.AreEqual(3, i); }
public void MixedVector() { Check(new byte[] { 3, 102, 111, 111, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 251, 255, 255, 255, 255, 255, 255, 255, 205, 204, 204, 204, 204, 204, 244, 63, 1, 0, 0, 0, 0, 0, 0, 0, 20, 4, 4, 15, 104, 45, 43, 1 }, FlexBuffer.From(new List <object> { "foo", 1, -5, 1.3, true })); }
public void DictionaryWithCapitalAndNonCapitalKeyValues() { Dictionary <string, object> dict = new Dictionary <string, object>(); dict.Add("aieorjhioa", "aerhj"); dict.Add("e98rh8d9i3qaktgr", "eaihjor"); dict.Add("T", "toeks"); byte[] testBytes = FlexBuffer.From(dict); FlxMap map = FlxValue.FromBytes(testBytes).AsMap; Assert.AreEqual("aerhj", map["aieorjhioa"].AsString); Assert.AreEqual("eaihjor", map["e98rh8d9i3qaktgr"].AsString); Assert.AreEqual("toeks", map["T"].AsString); }
public void MixedArray() { var value = new object[] { "Max", 1, 0.1, 0.5, true, int.MinValue, ulong.MaxValue, "Hi 😂🤣😍🤪", null }; var bytes = FlexBuffer.From(value); var flx = FlxValue.FromBytes(bytes); Assert.AreEqual(value.Length, flx.AsVector.Length); Assert.AreEqual(value[0], flx[0].AsString); Assert.AreEqual(value[1], flx[1].AsLong); Assert.AreEqual(value[2], flx[2].AsDouble); Assert.AreEqual(value[3], flx[3].AsDouble); Assert.AreEqual(value[4], flx[4].AsBool); Assert.AreEqual(value[5], flx[5].AsLong); Assert.AreEqual(value[6], flx[6].AsULong); Assert.AreEqual(value[7], flx[7].AsString); Assert.AreEqual(true, flx[8].IsNull); }
public void BiggerDictionary() { var dict = new Dictionary <string, int>(); for (var i = 0; i < 2600; i++) { dict[i.ToString()] = i; } var bytes = FlexBuffer.From(dict); var flx = FlxValue.FromBytes(bytes); Assert.AreEqual(2600, flx.AsMap.Length); for (var i = 0; i < 2600; i++) { Assert.AreEqual(i, flx[i.ToString()].AsLong); } }
public void BiggerBoolArray() { var list = new List <bool>(); for (var i = 0; i < 2600; i++) { list.Add(i % 3 == 0); } var bytes = FlexBuffer.From(list); var flx = FlxValue.FromBytes(bytes); Assert.AreEqual(2600, flx.AsVector.Length); for (var i = 0; i < 2600; i++) { Assert.AreEqual(list[i], flx[i].AsBool); } }
public void BiggerStringArray() { var list = new List <string>(); for (var i = 0; i < 2600; i++) { list.Add("abc"); } var bytes = FlexBuffer.From(list); var flx = FlxValue.FromBytes(bytes); Assert.AreEqual(2600, flx.AsVector.Length); for (var i = 0; i < 2600; i++) { Assert.AreEqual("abc", flx[i].AsString); } }
public void IterateOverMap() { var dict = new Dictionary <string, int>() { { "a", 1 }, { "b", 2 }, { "c", 3 }, }; var bytes = FlexBuffer.From(dict); var flx = FlxValue.FromBytes(bytes); var i = 0; foreach (var value in flx.AsMap) { Assert.AreEqual(dict[value.Key], value.Value.AsLong); i++; } Assert.AreEqual(3, i); }
public void GetValueIndex() { var dict = new Dictionary <string, int>() { { "a", 1 }, { "b", 2 }, { "c", 3 }, }; var bytes = FlexBuffer.From(dict); var flx = FlxValue.FromBytes(bytes); var map = flx.AsMap; Assert.AreEqual(3, map.Length); Assert.AreEqual(0, map.KeyIndex("a")); Assert.AreEqual(1, map.KeyIndex("b")); Assert.AreEqual(2, map.KeyIndex("c")); Assert.AreEqual(-1, map.KeyIndex("d")); Assert.AreEqual(1, map.ValueByIndex(0).AsLong); }
public void TestPrettyJson2DVector() { var list = new List <List <int> > { new List <int>() { 1, 2, 3 }, new List <int>() { 5, 6 }, new List <int>() { 7, 8, 9, 10 }, }; var expected = @"[ [ 1, 2, 3 ], [ 5, 6 ], [ 7, 8, 9, 10 ] ]".Replace("\r", ""); var bytes = FlexBuffer.From(list); var flx = FlxValue.FromBytes(bytes); Assert.AreEqual(expected, flx.ToPrettyJson()); }
public void VectorOfSameKeyDicts() { var dict = new List <Dictionary <string, int> >() { new Dictionary <string, int>() { { "something", 12 } }, new Dictionary <string, int>() { { "something", 45 } } }; Check( new byte[] { 115, 111, 109, 101, 116, 104, 105, 110, 103, 0, 1, 11, 1, 1, 1, 12, 4, 6, 1, 1, 45, 4, 2, 8, 4, 36, 36, 4, 40, 1 }, FlexBuffer.From(dict)); }
public void ComplexMap() { var value = new Dictionary <string, dynamic>() { { "age", 35 }, { "flags", new bool[] { true, false, true, true } }, { "weight", 72.5 }, { "name", "Maxim" }, { "address", new Dictionary <string, dynamic>() { { "city", "Bla" }, { "zip", "12345" }, { "countryCode", "XX" }, } }, }; // Different in Swift Check( new byte[] { 97, 103, 101, 0, 102, 108, 97, 103, 115, 0, 4, 1, 0, 1, 1, 119, 101, 105, 103, 104, 116, 0, 110, 97, 109, 101, 0, 5, 77, 97, 120, 105, 109, 0, 97, 100, 100, 114, 101, 115, 115, 0, 99, 105, 116, 121, 0, 3, 66, 108, 97, 0, 122, 105, 112, 0, 5, 49, 50, 51, 52, 53, 0, 99, 111, 117, 110, 116, 114, 121, 67, 111, 100, 101, 0, 2, 88, 88, 0, 3, 38, 18, 30, 3, 1, 3, 38, 11, 31, 20, 20, 20, 5, 59, 94, 91, 74, 82, 0, 0, 7, 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0, 26, 0, 0, 0, 35, 0, 0, 0, 109, 0, 0, 0, 96, 0, 0, 0, 0, 0, 145, 66, 36, 4, 144, 20, 14, 25, 38, 1 }, FlexBuffer.From(value)); }
public void ComplexMapToJson() { var value = new Dictionary <string, dynamic>() { { "age", 35 }, { "flags", new[] { true, false, true, true } }, { "weight", 72.5 }, { "name", "Maxim" }, { "address", new Dictionary <string, dynamic>() { { "city", "Bla" }, { "zip", "12345" }, { "countryCode", "XX" }, } }, { "something", null } }; var bytes = FlexBuffer.From(value); var flx = FlxValue.FromBytes(bytes); const string expected = "{\"address\":{\"city\":\"Bla\",\"countryCode\":\"XX\",\"zip\":\"12345\"},\"age\":35,\"flags\":[true,false,true,true],\"name\":\"Maxim\",\"something\":null,\"weight\":72.5}"; var json = flx.ToJson; Assert.AreEqual(expected, json); }
public void StringVectorWithRepeatingStrings() { Check(new byte[] { 3, 102, 111, 111, 0, 3, 98, 97, 114, 0, 3, 98, 97, 122, 0, 6, 15, 11, 7, 18, 14, 10, 6, 60, 1 }, FlexBuffer.From(new [] { "foo", "bar", "baz", "foo", "bar", "baz" })); }
public void StringVector() { Check(new byte[] { 3, 102, 111, 111, 0, 3, 98, 97, 114, 0, 3, 98, 97, 122, 0, 3, 15, 11, 7, 3, 60, 1 }, FlexBuffer.From(new [] { "foo", "bar", "baz" })); }
public void BoolVector() { Check(new byte[] { 3, 1, 0, 1, 3, 144, 1 }, FlexBuffer.From(new [] { true, false, true })); }
public void DoubleVector() { Check(new byte[] { 3, 0, 0, 0, 0, 0, 192, 63, 0, 0, 32, 64, 0, 0, 96, 64, 12, 54, 1 }, FlexBuffer.From(new [] { 1.5, 2.5, 3.5 })); Check(new byte[] { 3, 0, 0, 0, 0, 0, 0, 0, 154, 153, 153, 153, 153, 153, 241, 63, 154, 153, 153, 153, 153, 153, 1, 64, 102, 102, 102, 102, 102, 102, 10, 64, 24, 55, 1 }, FlexBuffer.From(new [] { 1.1, 2.2, 3.3 })); }