示例#1
0
        public void ReadByIgnoringBlankCharactersTest(object val, Func <object, bool> test)
        {
            var obj = new byte[3000];
            var buf = BssomSerializer.Serialize(obj);

            var bsfw = new BssomFieldMarshaller(buf);

            bsfw.TryWrite(BssomFieldOffsetInfo.Zero, val).IsTrue();
            test(BssomSerializer.Deserialize(buf, 0, out int readSize, val.GetType())).IsTrue();

            bsfw.TryWrite(BssomFieldOffsetInfo.Zero, val).IsTrue();
            test(BssomSerializer.Deserialize(buf, 0, out readSize, val.GetType())).IsTrue();
        }
示例#2
0
        [InlineData(typeof(int), typeof(List <DateTime>))] //Array1
        public void Array1_WriteField_ElementTypeMustCompleteConsistency_IsRequiredToWrite(Type eleType, Type arrayType)
        {
            var val = RandomHelper.RandomValue(arrayType);
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);
            var ran  = RandomHelper.RandomValue(eleType);

            VerifyHelper.Throws <InvalidCastException>(() => bsfm.TryWrite(bsfm.IndexOf("$0"), ran));
        }
示例#3
0
        public void Map_WriteFieldWithBlankLength_InsufficientLengthWritten_IsCorrectly()
        {
            var val = RandomHelper.RandomValue <_class2>();
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);

            long A1 = RandomHelper.RandomValue <long>();

            bsfm.TryWrite(bsfm.IndexOf("[" + nameof(_class2.A) + "]"), A1).IsFalse();
        }
示例#4
0
        public void Map_WriteField_TypeAndTypeLengthIsSame_IsCorrectly()
        {
            var val = RandomHelper.RandomValue <_class1>();
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);

            var val2 = RandomHelper.RandomValue <_class1>();

            bsfm.TryWrite(bsfm.IndexOf("[" + nameof(_class1.A) + "]"), val2.A).IsTrue();
            bsfm.TryWrite(bsfm.IndexOf("[" + nameof(_class1.B123123123) + "]"), val2.B123123123).IsTrue();
            bsfm.TryWrite(bsfm.IndexOf("[" + nameof(_class1.B1231231VV) + "]"), val2.B1231231VV).IsTrue();
            bsfm.TryWrite(bsfm.IndexOf("[" + nameof(_class1.C) + "]"), val2.C).IsTrue();

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

            val3.A.Is(val2.A);
            val3.B123123123.Is(val2.B123123123);
            val3.B1231231VV.Is(val2.B1231231VV);
            val3.C.Is(val2.C);
        }
示例#5
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);
        }
示例#6
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);
        }
示例#7
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));
        }
示例#8
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);
        }
示例#9
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));
        }
示例#10
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);
            }
        }
示例#11
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);
            }
        }
示例#12
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);
        }
示例#13
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);
        }
示例#14
0
 public void WriteField()
 {
     BssomFieldMarshaller.TryWrite(OutPut, 0, OutPut.Length, UpdateDateOffsetInfo, DateTime.Now);
 }