예제 #1
0
        public void Map2_ReadStrongType_FunctionIsCorrectly()
        {
            var val = RandomHelper.RandomValue <_class1>();
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);

            bsfm.ReadValue <DateTime>(bsfm.IndexOf("[" + nameof(_class1.A) + "]")).Is(val.A);
            bsfm.ReadValue <Guid>(bsfm.IndexOf("[" + nameof(_class1.B123123123) + "]")).Is(val.B123123123);
            bsfm.ReadValue <int>(bsfm.IndexOf("[" + nameof(_class1.B1231231VV) + "]")).Is(val.B1231231VV);
            bsfm.ReadValue <int>(bsfm.IndexOf("[" + nameof(_class1.C) + "]")).Is(val.C);
        }
예제 #2
0
        public void Map2_ReadBssomValue_FunctionIsCorrectly()
        {
            var val = RandomHelper.RandomValue <_class1>();
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);

            bsfm.ReadValue <BssomValue>(bsfm.IndexOf("[" + nameof(_class1.A) + "]")).Is(BssomValue.Create(val.A));
            bsfm.ReadValue <BssomValue>(bsfm.IndexOf("[" + nameof(_class1.B123123123) + "]")).Is(BssomValue.Create(val.B123123123));
            bsfm.ReadValue <BssomValue>(bsfm.IndexOf("[" + nameof(_class1.B1231231VV) + "]")).Is(BssomValue.Create(val.B1231231VV));
            bsfm.ReadValue <BssomValue>(bsfm.IndexOf("[" + nameof(_class1.C) + "]")).Is(BssomValue.Create(val.C));
        }
예제 #3
0
        public void Map1_ReadBssomValue_FunctionIsCorrectly()
        {
            var val = new Dictionary <string, object>()
            {
                { "A", (int)3 },
                { "B", (DateTime)DateTime.MaxValue },
                { "C", (string)"1234567" }
            };

            var option = BssomSerializerOptions.Default.WithIDictionaryIsSerializeMap1Type(true);
            var buf    = BssomSerializer.Serialize(val, option);

            var bsfm = new BssomFieldMarshaller(buf);

            bsfm.ReadValue <BssomValue>(bsfm.IndexOf("[A]")).Is(BssomValue.Create(val["A"]));
            bsfm.ReadValue <BssomValue>(bsfm.IndexOf("[B]")).Is(BssomValue.Create(val["B"]));
            bsfm.ReadValue <BssomValue>(bsfm.IndexOf("[C]")).Is(BssomValue.Create(val["C"]));
        }
예제 #4
0
        public void MixtureType_ReadStrongType_FunctionIsCorrectly()
        {
            var val = new List <Dictionary <string, int[]> >()
            {
                new Dictionary <string, int[]>()
                {
                    { "A", new int[] { 1, 2, 3 } },
                    { "B", new int[] { 4, 5, 6 } }
                },
                new Dictionary <string, int[]>()
                {
                    { "A2", new int[] { 1, 2, 3 } },
                    { "B2", new int[] { 4, 5, 6 } }
                }
            };
            var buf  = BssomSerializer.Serialize(val);
            var bsfm = new BssomFieldMarshaller(buf);

            bsfm.ReadValue <int>(bsfm.IndexOf("$0[A]$0")).Is(1);
            bsfm.ReadValue <int>(bsfm.IndexOf("$0[A]$1")).Is(2);
            bsfm.ReadValue <int>(bsfm.IndexOf("$0[B]$2")).Is(6);

            bsfm.ReadValue <int>(bsfm.IndexOf("$1[A2]$0")).Is(1);
            bsfm.ReadValue <int>(bsfm.IndexOf("$1[A2]$1")).Is(2);
            bsfm.ReadValue <int>(bsfm.IndexOf("$1[B2]$2")).Is(6);
        }
예제 #5
0
        [InlineData(typeof(List <object>))]   //Array2
        public void Array_ReadBssomValue_FunctionIsCorrectly(Type type)
        {
            var val = RandomHelper.RandomValue(type);
            var buf = BssomSerializer.Serialize(val);

            var bsfm  = new BssomFieldMarshaller(buf);
            int count = ((ICollection)val).Count;

            for (int i = 0; i < count; i++)
            {
                bsfm.ReadValue <BssomValue>(bsfm.IndexOf($"${i}")).Is(BssomValue.Create(((IList)val)[i]));
            }
        }
예제 #6
0
        public void Array1_ReadStrongType_FunctionIsCorrectly()
        {
            var val = RandomHelper.RandomValue <List <byte> >();
            var buf = BssomSerializer.Serialize(val);

            var bsfm  = new BssomFieldMarshaller(buf);
            int count = ((ICollection)val).Count;

            for (int i = 0; i < count; i++)
            {
                bsfm.ReadValue <byte>(bsfm.IndexOf($"${i}")).Is(val[i]);
            }
        }
예제 #7
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);
        }
예제 #8
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);
        }
예제 #9
0
        [InlineData("12345678901234567")]//17size-> Blank0 critical value
        public void Array2_WriteFieldWithBlankLength_MultipleWritesOfInconsistentLength_IsCorrectly(object fieldValue)
        {
            var val = new List <string>();//18size

            val.Add("123456789012345678");
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);

            var cOffset = bsfm.IndexOf("$0");

            bsfm.TryWrite(cOffset, fieldValue).IsTrue();
            bsfm.ReadValue <BssomValue>(cOffset).Is(BssomValue.Create(fieldValue));
        }
예제 #10
0
        public void Array2_WriteFieldWithBlankLength_EmptyInt32Code_Test()
        {
            var val = new List <byte[]> {
                new byte[short.MaxValue + 1]
            };
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);

            int num = 3;
            var of  = bsfm.IndexOf("$0");

            bsfm.TryWrite(of, num).IsTrue();
            bsfm.ReadValue <int>(of).Is(num);
        }
예제 #11
0
        [InlineData("12345678901234567")]//17size-> Blank0 critical value
        public void Map_WriteFieldWithBlankLength_MultipleWritesOfInconsistentLength_IsCorrectly(object fieldValue)
        {
            var val = new _class2()
            {
                C = "123456789012345678"
            };                                                   //18size
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);

            var cOffset = bsfm.IndexOf("[" + nameof(_class2.C) + "]");

            bsfm.TryWrite(cOffset, fieldValue).IsTrue();
            bsfm.ReadValue <BssomValue>(cOffset).Is(BssomValue.Create(fieldValue));
        }
예제 #12
0
        public void Map_ReadAllKeysByMapType_IsCorrectly(bool isSerializeMap1Type)
        {
            var val = RandomHelper.RandomValueWithOutStringEmpty <Dictionary <string, int> >();
            var buf = BssomSerializer.Serialize(val, BssomSerializerOptions.Default.WithIDictionaryIsSerializeMap1Type(isSerializeMap1Type));

            var bsfm = new BssomFieldMarshaller(buf);
            var keys = bsfm.ReadAllKeysByMapType <string>(BssomFieldOffsetInfo.Zero);

            foreach (var item in keys)
            {
                val.TryGetValue(item.Key, out int itemVal).IsTrue();
                itemVal.Is(bsfm.ReadValue <int>(item.Value));
                val.Remove(item.Key).IsTrue();
            }
        }
예제 #13
0
        [InlineData(typeof(DateTime), typeof(List <DateTime>))] //Array1
        public void Array1_WriteField_TypeAndTypeLengthIsSame_IsCorrectly(Type eleType, Type arrayType)
        {
            var val = RandomHelper.RandomValue(arrayType);
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);

            var list = (IList)val;

            for (int i = 0; i < list.Count; i++)
            {
                var ran = RandomHelper.RandomValue(eleType);
                bsfm.TryWrite(bsfm.IndexOf($"${i}"), ran).IsTrue();
                bsfm.ReadValue <object>(bsfm.IndexOf($"${i}")).Is(ran);
            }
        }
예제 #14
0
        [InlineData(typeof(byte), typeof(List <List <object> >))] //Array2
        public void Array2_WriteFieldWithBlankLength_IsExtraLengthWriting_IsCorrectly(Type eleType, Type arrayType)
        {
            var val = RandomHelper.RandomValueWithOutStringEmpty(arrayType);
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);

            var list = (IList)val;

            for (int i = 0; i < list.Count; i++)
            {
                var ran   = RandomHelper.RandomValue(eleType);
                var index = bsfm.IndexOf($"${i}");
                bsfm.TryWrite(index, ran).IsTrue();
                bsfm.ReadValue <object>(index).Is(ran);
            }
        }
예제 #15
0
        public void Map_WriteFieldWithBlankLength_IsExtraLengthWriting_FixTypeSize_IsCorrectly()
        {
            var val = RandomHelper.RandomValue <_class2>();
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);


            int B1 = RandomHelper.RandomValue <int>();

            bsfm.TryWrite(bsfm.IndexOf("[" + nameof(_class2.B) + "]"), B1).IsTrue();

            var val3 = BssomSerializer.Deserialize <BssomMap>(buf);

            val3["B"].Is(BssomValue.Create(B1));
            bsfm.ReadValue <int>(bsfm.IndexOf("[" + nameof(_class2.B) + "]")).Is(B1);
        }
예제 #16
0
        public void Map_WriteFieldWithBlankLength_IsExtraLengthWriting_VariableTypeSize_IsCorrectly()
        {
            var val = new _class2()
            {
                C = "123456789"
            };
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);


            string C1 = "123";

            bsfm.TryWrite(bsfm.IndexOf("[" + nameof(_class2.C) + "]"), C1).IsTrue();

            var val3 = BssomSerializer.Deserialize <BssomMap>(buf);

            val3["C"].Is(BssomValue.Create(C1));
            bsfm.ReadValue <string>(bsfm.IndexOf("[" + nameof(_class2.C) + "]")).Is(C1);
        }
예제 #17
0
        public void Array3_IndexOf_FunctionIsCorrectly()
        {
            var val = RandomHelper.RandomValue <_spacingValuesClass>();

            val.D = new Dictionary <string, string>()
            {
                { "_1", "1" }, { "_2", "2" }
            };
            var buf = BssomSerializer.Serialize(val, BssomSerializerOptions.IntKeyCompositedResolverOption);

            var bsfm = new BssomFieldMarshaller(buf);

            bsfm.ReadValue <Int32>(bsfm.IndexOf("$0")).Is(val.A);
            bsfm.ReadValue <object>(bsfm.IndexOf("$1")).Is(null);
            bsfm.ReadValue <object>(bsfm.IndexOf("$2")).Is(null);
            bsfm.ReadValue <Int32>(bsfm.IndexOf("$3")).Is(val.B);
            bsfm.ReadValue <object>(bsfm.IndexOf("$4")).Is(null);
            bsfm.ReadValue <Int32>(bsfm.IndexOf("$5")).Is(val.C);
            bsfm.ReadValue <string>(bsfm.IndexOf("$6[_2]")).Is("2");
        }
예제 #18
0
 public void ReadField()
 {
     BssomFieldMarshaller.ReadValue <DateTime>(OutPut, 0, OutPut.Length, UpdateDateOffsetInfo);
 }