Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }