示例#1
0
        public ComplexTypeBenchmarks()
        {
            this.orleansSerializer = new ClientBuilder()
                                     .ConfigureDefaults()
                                     .UseLocalhostClustering()
                                     .Configure <ClusterOptions>(o => o.ClusterId = o.ServiceId = "test")
                                     .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(SimpleClass).Assembly).WithCodeGeneration())
                                     .Build().ServiceProvider.GetRequiredService <SerializationManager>();
            var services = new ServiceCollection();

            services
            .AddHagar()
            .AddISerializableSupport()
            .AddSerializers(typeof(Program).Assembly);
            var serviceProvider = services.BuildServiceProvider();

            this.hagarSerializer  = serviceProvider.GetRequiredService <Serializer <ComplexClass> >();
            this.structSerializer = serviceProvider.GetRequiredService <Serializer <SimpleStruct> >();
            this.sessionPool      = serviceProvider.GetRequiredService <SessionPool>();
            this.value            = new ComplexClass
            {
                BaseInt = 192,
                Int     = 501,
                String  = "bananas",
                //Array = Enumerable.Range(0, 60).ToArray(),
                //MultiDimensionalArray = new[,] {{0, 2, 4}, {1, 5, 6}}
            };
            this.value.AlsoSelf = this.value.BaseSelf = this.value.Self = this.value;

            this.structValue = new SimpleStruct
            {
                Int  = 42,
                Bool = true,
                Guid = Guid.NewGuid()
            };
            this.session = sessionPool.GetSession();
            var writer = new Writer(HagarBuffer);

            this.hagarSerializer.Serialize(this.value, session, ref writer);
            var bytes = new byte[HagarBuffer.GetMemory().Length];

            HagarBuffer.GetReadOnlySequence().CopyTo(bytes);
            this.hagarBytes = new ReadOnlySequence <byte>(bytes);
            HagarBuffer.Reset();

            var writer2 = new BinaryTokenStreamWriter();

            this.orleansSerializer.Serialize(this.value, writer2);
            this.orleansBytes = writer2.ToBytes();

            this.readBytesLength = Math.Min(bytes.Length, orleansBytes.Sum(x => x.Count));
        }
示例#2
0
        public void SerializeStruct()
        {
            var writer = new Writer(HagarBuffer);

            session.FullReset();
            this.structSerializer.Serialize(this.structValue, session, ref writer);

            session.FullReset();
            var reader = new Reader(HagarBuffer.GetReadOnlySequence());

            this.structSerializer.Deserialize(session, ref reader);
            HagarBuffer.Reset();
        }
示例#3
0
        public void SerializeComplex()
        {
            var writer = new Writer(HagarBuffer);

            session.FullReset();
            this.hagarSerializer.Serialize(this.value, session, ref writer);

            session.FullReset();
            var reader = new Reader(new ReadOnlySequence <byte>(HagarBuffer.GetMemory()));

            this.hagarSerializer.Deserialize(session, ref reader);
            HagarBuffer.Reset();
        }