Esempio n. 1
0
        public void SizeTestWithContext()
        {
            int val = int.MaxValue;
            BssomSizeContext context = new BssomSizeContext();

            BssomSerializer.Size(ref context, val).Is(5);
        }
Esempio n. 2
0
        public static void VerifySpecific <T>(Lazy <T> value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            BssomSerializer.Deserialize <Lazy <T> >(buf, option).Value.Is(value.Value);
        }
Esempio n. 3
0
        public static void VerifyNullableIsNull <T>(BssomSerializerOptions option = null) where T : struct
        {
            var buf = BssomSerializer.Serialize <Nullable <T> >(null, option);

            BssomSerializer.Size <Nullable <T> >(null, option).Is(1).Is(buf.Length);
            BssomSerializer.Deserialize <Nullable <T> >(buf, option).IsNull();
        }
Esempio n. 4
0
        public static void VerifySimpleType <T>(T value, int size, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(size).Is(buf.Length);
            BssomSerializer.Deserialize <T>(buf, option).Is(value);
        }
Esempio n. 5
0
        public static void VerifyTypeNull <T>(BssomSerializerOptions option = null) where T : class
        {
            var buf = BssomSerializer.Serialize <T>(null, option);

            BssomSerializer.Size <T>(null, option).Is(1).Is(buf.Length);
            BssomSerializer.Deserialize <T>(buf, option).IsNull();
        }
Esempio n. 6
0
        private static byte[] SimplicityVerify <T>(T value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            BssomSerializer.Deserialize <T>(buf, option).Is(value);
            return(buf);
        }
Esempio n. 7
0
        public static void VerifyIDictWithMap2Type(IDictionary value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            BssomSerializer.Deserialize <IDictionary>(buf, option).GetGetEnumerator().IsDict(value.GetGetEnumerator());
            buf.IsMap2();
        }
Esempio n. 8
0
        public static byte[] VerifyIDictAndReturnSerializeBytes(IDictionary value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            BssomSerializer.Deserialize <IDictionary>(buf, option).GetGetEnumerator().IsDict(value.GetGetEnumerator());
            return(buf);
        }
Esempio n. 9
0
        public static byte[] VerifyIDictAndReturnSerializeBytes <T, TKey, TValue>(T value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            ((IEnumerable <KeyValuePair <TKey, TValue> >)BssomSerializer.Deserialize <T>(buf, option)).IsDict((IEnumerable <KeyValuePair <TKey, TValue> >)value);
            return(buf);
        }
Esempio n. 10
0
        public static BssomValueType ConvertObjectAndVerifyBssomValueType <T>(T value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize <object>(value, option);

            BssomSerializer.Size <object>(value, option).Is(buf.Length);
            ((T)BssomSerializer.Deserialize <object>(buf, (option ?? BssomSerializerOptions.Default).WithIsPriorityToDeserializeObjectAsBssomValue(false))).Is(value);
            (BssomSerializer.Deserialize <object>(buf, (option ?? BssomSerializerOptions.Default).WithIsPriorityToDeserializeObjectAsBssomValue(true))).Is(BssomValue.Create(value));
            return(new BssomFieldMarshaller(buf).ReadValueType(BssomFieldOffsetInfo.Zero));
        }
Esempio n. 11
0
        public static void VerifyArray(BssomArray value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            var ary = (BssomArray)BssomSerializer.Deserialize <object>(buf, option);

            ary.IsArray(value);
        }
Esempio n. 12
0
        public static void VerifyMap(BssomMap value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            var map = (BssomMap)BssomSerializer.Deserialize <object>(buf, option);

            value.IsMap(map);
        }
Esempio n. 13
0
        public static void ConvertObjectAndVerifyEntity(object value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            buf.IsMap2();
            var map = (BssomMap)BssomSerializer.Deserialize <object>(buf, option);

            value.GetPublicMembersWithDynamicObject().IsMap(map);
        }
Esempio n. 14
0
        private static byte[] UseJsonToolForValidation <T>(T value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            var t = BssomSerializer.Deserialize <T>(buf, option);

            Kooboo.Json.JsonSerializer.ToJson(t).Is(Kooboo.Json.JsonSerializer.ToJson(value));
            return(buf);
        }
Esempio n. 15
0
        public static void VerifySpecific(StringDictionary value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            var dict  = new Dictionary <string, string>(BssomSerializer.Deserialize <StringDictionary>(buf, option).ToIEnumerable().ToIDict());
            var dict2 = new Dictionary <string, string>(value.ToIEnumerable().ToIDict());

            dict.IsDict(dict2);
        }
Esempio n. 16
0
        public static void VerifySpecific <T>(IGrouping <T, T> value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            var group = BssomSerializer.Deserialize <IGrouping <T, T> >(buf, option);

            group.Key.Is(value.Key);
            group.Is(value);
        }
Esempio n. 17
0
        public void MultipleStringTryWrite_LastElementIsWriteStringWithNotPredictingLength()
        {
            var str = new string[] { "a", "b12345678" };
            var buf = BssomSerializer.Serialize(str);

            buf.Length.Is(BssomSerializer.Size(str));//Simulate StringSize

            var bsfw = new BssomFieldMarshaller(buf);

            bsfw.TryWrite(BssomFieldOffsetInfo.Zero, str).IsTrue();//first element is fast stringwrite, last element is notPredicting(slow) write
            bsfw.ReadValueSize(BssomFieldOffsetInfo.Zero).Is(buf.Length);
            bsfw.ReadValue <string[]>(BssomFieldOffsetInfo.Zero).Is(str);
        }
Esempio n. 18
0
        public void WriteStringWithNotPredictingLengthTest()
        {
            var str = RandomHelper.RandomValueWithOutStringEmpty <string>();
            var buf = BssomSerializer.Serialize(str);

            buf.Length.Is(BssomSerializer.Size(str));//Simulate StringSize

            var bsfw = new BssomFieldMarshaller(buf);

            bsfw.TryWrite(BssomFieldOffsetInfo.Zero, str).IsTrue();// is call WriteStringWithNotPredictingLength
            bsfw.ReadValueSize(BssomFieldOffsetInfo.Zero).Is(buf.Length);
            bsfw.ReadValue <string>(BssomFieldOffsetInfo.Zero).Is(str);
        }
Esempio n. 19
0
        public static void VerifySpecific <T>(ILookup <T, T> value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            var val = BssomSerializer.Deserialize <ILookup <T, T> >(buf, option);

            val.Count.Is(value.Count);
            foreach (var item in value)
            {
                VerifySpecific(item, option);
            }
        }
Esempio n. 20
0
        public static void VerifySize(object value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            buf.Length.Is(BssomSerializer.Size(value, option));

            var reader = new BssomReader(new SimpleBufferWriter(buf));

            reader.SkipObject();
            reader.Position.Is(buf.Length);

            var bsfm = new BssomFieldMarshaller(buf);

            bsfm.ReadValueSize(BssomFieldOffsetInfo.Zero).Is(buf.Length);
        }
Esempio n. 21
0
        public static BssomArray ConvertArray3ObjectAndVerifyEntity <T>(T value, BssomSerializerOptions option = null)
        {
            if (option == null)
            {
                option = BssomSerializerOptions.IntKeyCompositedResolverOption;
            }
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            buf.IsArray3();
            var desObj = BssomSerializer.Deserialize <T>(buf, option);

            Kooboo.Json.JsonSerializer.ToJson(value).Is(Kooboo.Json.JsonSerializer.ToJson(desObj));
            return(BssomSerializer.Deserialize <BssomArray>(buf, option));
        }
Esempio n. 22
0
        public static BssomValueType ConvertObjectAndVerifyBssomMapType <TKey, TValue>(object value, BssomSerializerOptions option = null)
        {
            if (option == null)
            {
                option = BssomSerializerOptions.Default;
            }

            var buf = BssomSerializer.Serialize <object>(value, option);

            BssomSerializer.Size <object>(value, option).Is(buf.Length);

            var dicObj = ((IEnumerable <KeyValuePair <object, object> >)BssomSerializer.Deserialize <object>(buf, option.WithIsPriorityToDeserializeObjectAsBssomValue(false))).Select(e => new KeyValuePair <TKey, TValue>((TKey)e.Key, (TValue)e.Value));

            dicObj.IsDict((IEnumerable <KeyValuePair <TKey, TValue> >)value);
            var dicObj2 = ((IEnumerable <KeyValuePair <object, object> >)BssomSerializer.Deserialize <object>(buf, option.WithIsPriorityToDeserializeObjectAsBssomValue(true)));

            dicObj2.IsDict((IDictionary <object, object>)BssomValue.Create(value));
            return(new BssomFieldMarshaller(buf).ReadValueType(BssomFieldOffsetInfo.Zero));
        }
Esempio n. 23
0
        public void FieldTypeFormatterAttribute_Test()
        {
            var val = new _Attribute_Class_4()
            {
                Name    = "a",
                Address = "b",
                Age     = 10,
                Sex     = 1
            };
            var buf = BssomSerializer.Serialize(val);

            BssomSerializer.Size(val).Is(buf.Length);
            var t = BssomSerializer.Deserialize <_Attribute_Class_4>(buf);

            t.Name.Is("a");
            t.Address.Is("b");
            t.Age.Is(6);
            t.Sex.Is(1);
        }
Esempio n. 24
0
        public void MyTest()
        {
            var              option      = BssomSerializerOptions.Default.WithFormatterResolver(MyStringFormatterResolver.Instance);
            string           str         = RandomHelper.RandomValue <string>();
            BssomSizeContext sizeContext = new BssomSizeContext(option);
            int              len         = BssomSerializer.Size(ref sizeContext, str);

            if (len > 1000)
            {
                throw new Exception("Size of value storage binary exceeded");
            }

            BssomSerializeContext serContext = new BssomSerializeContext(option);

            sizeContext.ContextDataSlots.SetMyStringStack(serContext.ContextDataSlots);
            var bytes = BssomSerializer.Serialize(ref serContext, str);
            var deStr = BssomSerializer.Deserialize <string>(bytes);

            Assert.Equal(str, deStr);
        }
Esempio n. 25
0
        public static BssomValueType ConvertArrayObjectAndVerifyBssomValueType <T>(T value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize <object>(value, option);

            BssomSerializer.Size <object>(value, option).Is(buf.Length);
            var ary = (BssomSerializer.Deserialize <object>(buf, (option ?? BssomSerializerOptions.Default).WithIsPriorityToDeserializeObjectAsBssomValue(false)));

            ary.Is(value);
            var ary2 = (BssomArray)(BssomSerializer.Deserialize <object>(buf, (option ?? BssomSerializerOptions.Default).WithIsPriorityToDeserializeObjectAsBssomValue(true)));

            var _ary2 = (BssomArray)BssomValue.Create(value);

            ary2.Count.Is(_ary2.Count);
            for (int i = 0; i < ary2.Count; i++)
            {
                ary2[i].Is(_ary2[i]);
            }
            //ary2.Is((IList<object>)BssomValue.Create(value));
            return(new BssomFieldMarshaller(buf).ReadValueType(BssomFieldOffsetInfo.Zero));
        }
Esempio n. 26
0
        public void AnonymousTypeFormatter_Formatter_IsCorrectly(bool isSerializeMap1Type)
        {
            var option   = BssomSerializerOptions.Default.WithIDictionaryIsSerializeMap1Type(isSerializeMap1Type);
            var testData = new { A = 600, CA = true, BD = new { Num = 7, TC = 17 }, EF = "oaoaoaoa" };

            var buf = BssomSerializer.Serialize(testData, option);

            BssomSerializer.Size(testData, option).Is(buf.Length);
            var map = (BssomMap)BssomSerializer.Deserialize <object>(buf, option);

            map.Count.Is(4);
            map["A"].Is(600);
            map["CA"].Is(true);
            map["BD"].IsType <BssomMap>();
            var bmap = (BssomMap)map["BD"];

            bmap.Count.Is(2);
            bmap["Num"].Is(7);
            bmap["TC"].Is(17);
            map["EF"].Is("oaoaoaoa");
        }
Esempio n. 27
0
        public void SizeTest()
        {
            int val = int.MaxValue;

            BssomSerializer.Size(val).Is(5);
        }