예제 #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.");
        }
예제 #2
0
        public ManualVersionToleranceTests(ITestOutputHelper log)
        {
            _log = log;
            var serviceCollection = new ServiceCollection();

            _serviceCollection = serviceCollection;
            _ = _serviceCollection.AddSerializer(builder =>
            {
                _ = builder.Configure(configuration =>
                {
                    _ = configuration.Serializers.Add(typeof(SubTypeSerializer));
                    _ = configuration.Serializers.Add(typeof(BaseTypeSerializer));
                    _ = configuration.Serializers.Add(typeof(ObjectWithNewFieldTypeSerializer));
                    _ = configuration.Serializers.Add(typeof(ObjectWithoutNewFieldTypeSerializer));

                    // Intentionally remove the generated serializer for these type. It will be added back during tests.
                    configuration.Serializers.RemoveWhere(s => typeof(IFieldCodec <ObjectWithNewField>).IsAssignableFrom(s));
                    configuration.Serializers.RemoveWhere(s => typeof(IFieldCodec <ObjectWithoutNewField>).IsAssignableFrom(s));
                });
            });

            _serviceProvider = _serviceCollection.BuildServiceProvider();

            _codecProvider = _serviceProvider.GetRequiredService <CodecProvider>();
            _serializer    = _codecProvider.GetCodec <SubType>();
        }