Exemplo n.º 1
0
        private void TestSkip(SubType expected)
        {
            using var writerSession = GetSession();
            var pipe   = new Pipe();
            var writer = Writer.Create(pipe.Writer, writerSession);

            _serializer.WriteField(ref writer, 0, typeof(SubType), expected);
            writer.Commit();

            _ = pipe.Writer.FlushAsync().AsTask().GetAwaiter().GetResult();
            var objectWithNewFieldSerializer    = _codecProvider.GetCodec <ObjectWithNewField>();
            var objectWithoutNewFieldSerializer = _codecProvider.GetCodec <ObjectWithoutNewField>();

            pipe.Writer.Complete();
            _ = pipe.Reader.TryRead(out var readResult);
            using var readerSession = GetSession();
            var reader        = Reader.Create(readResult.Buffer, readerSession);
            var initialHeader = reader.ReadFieldHeader();
            var skipCodec     = new SkipFieldCodec();

            _ = skipCodec.ReadValue(ref reader, initialHeader);
            pipe.Reader.AdvanceTo(readResult.Buffer.End);
            pipe.Reader.Complete();
            Assert.Equal(writer.Session.ReferencedObjects.CurrentReferenceId, reader.Session.ReferencedObjects.CurrentReferenceId);
            _log.WriteLine($"Skipped {reader.Position} bytes.");
        }
Exemplo n.º 2
0
        static void TestSkip(Func <SerializerSession> getSession, IFieldCodec <SubType> serializer, SubType expected)
        {
            var session = getSession();
            var writer  = new Writer();

            serializer.WriteField(writer, session, 0, typeof(SubType), expected);

            var reader = new Reader(writer.ToBytes());
            var deserializationContext = getSession();
            var initialHeader          = reader.ReadFieldHeader(session);
            var skipCodec = new SkipFieldCodec();

            skipCodec.ReadValue(reader, deserializationContext, initialHeader);

            Console.WriteLine($"Skipped {reader.CurrentPosition}/{reader.Length} bytes.");
        }
Exemplo n.º 3
0
        static void TestSkip(Func <SerializerSession> getSession, IFieldCodec <SubType> serializer, SubType expected)
        {
            var session = getSession();
            var pipe    = new Pipe();
            var writer  = new Writer <PipeWriter>(pipe.Writer, session);

            serializer.WriteField(ref writer, 0, typeof(SubType), expected);

            pipe.Writer.FlushAsync().GetAwaiter().GetResult();
            pipe.Writer.Complete();
            pipe.Reader.TryRead(out var readResult);
            var reader        = new Reader(readResult.Buffer, getSession());
            var initialHeader = reader.ReadFieldHeader();
            var skipCodec     = new SkipFieldCodec();

            skipCodec.ReadValue(ref reader, initialHeader);
            pipe.Reader.AdvanceTo(readResult.Buffer.End);
            pipe.Reader.Complete();
            Console.WriteLine($"Skipped {reader.Position} bytes.");
        }
        private void TestSkip(SubType expected)
        {
            using var writerSession = GetSession();
            var pipe   = new Pipe();
            var writer = new Writer <PipeWriter>(pipe.Writer, writerSession);

            this.serializer.WriteField(ref writer, 0, typeof(SubType), expected);
            writer.Commit();

            pipe.Writer.FlushAsync().GetAwaiter().GetResult();
            pipe.Writer.Complete();
            pipe.Reader.TryRead(out var readResult);
            using var readerSession = GetSession();
            var reader        = new Reader(readResult.Buffer, readerSession);
            var initialHeader = reader.ReadFieldHeader();
            var skipCodec     = new SkipFieldCodec();

            skipCodec.ReadValue(ref reader, initialHeader);
            pipe.Reader.AdvanceTo(readResult.Buffer.End);
            pipe.Reader.Complete();
            this.log.WriteLine($"Skipped {reader.Position} bytes.");
        }