Пример #1
0
        public async Task WriteAsync_Parallel(int totWorkerThreads, BufferedStreamWriterConfig sw_cfg, bool usingMemoryStream)
        {
            if (!usingMemoryStream)
            {
                FileHelper.FlushFileCache(tmpFilename_baseline);
            }
            else
            {
                ms_parallel.SetLength(ms_parallel.Length);
                ms_parallel.Position = 0;
            }
            FileHelper.FlushFileCache(tmpFilename_parallel);
            var opts = new FrameParallelOptions(totWorkerThreads, opts_standard.WithResolver(FrameResolverPlusStandarResolver.Instance));

            using (StreamChain sc = new StreamChain())
            {
                Stream s = sc.ComposeChain(
                    usingMemoryStream ? ms_parallel :
                    File.Open(tmpFilename_parallel, FileMode.Create, FileAccess.Write, FileShare.None), sw_cfg);
                await MessagePackSerializer.SerializeAsync(s, obj_parallel, opts);
            }
            if (usingMemoryStream)
            {
                ms_parallel.Flush();
                ms_parallel.Position = 0;
            }
        }
Пример #2
0
        public async Task <int> ReadAsync_Parallel(int totWorkerThreads, BufferedStreamReaderConfig config_r, bool usingMemoryStream)
        {
            if (!usingMemoryStream)
            {
                FileHelper.FlushFileCache(tmpFilename_parallel);
            }
            var opts = new FrameParallelOptions(
                totWorkerThreads, opts_standard.WithResolver(FrameResolverPlusStandarResolver.Instance));

            try
            {
                using (StreamChain sc1 = new StreamChain())
                {
                    Stream s = sc1.ComposeChain(
                        usingMemoryStream ? ms_parallel :
                        File.Open(tmpFilename_parallel, FileMode.Open, FileAccess.Read, FileShare.None), config_r);
                    var obj = await MessagePackSerializer.DeserializeAsync <T_Parallel>(s, opts);

                    return(obj.DoStuff());
                }
            }
            finally
            {
                if (usingMemoryStream)
                {
                    ms_parallel.Flush();
                    ms_parallel.Position = 0;
                }
            }
        }
        public static async Task <ArrayX> New_KnownLengthArray_ReadAsync(string fileName)
        {
            int totWorkerThreads = 2;
            var opts             = new FrameParallelOptions(totWorkerThreads, MessagePackSerializerOptions.Standard.WithResolver(FrameResolverPlusStandarResolver.Instance));

            using var stream = File.OpenRead(fileName);
            return(await MessagePackSerializer.DeserializeAsync <ArrayX>(stream, opts));
        }
        public static async Task New_KnownLengthArray_WriteAsync(string fileName)
        {
            int    totWorkerThreads = 2;
            var    opts             = new FrameParallelOptions(totWorkerThreads, MessagePackSerializerOptions.Standard.WithResolver(FrameResolverPlusStandarResolver.Instance));
            ArrayX obj = GetArrayX();

            using var s = File.Create(fileName);
            await MessagePackSerializer.SerializeAsync(s, obj, opts);
        }
        public void Deserialize_Parallel_FromParallelMatchesOriginal([Values] OuterContainerSampleType sampleType,
                                                                     [Values(1, 2, 3)] int totThreads, [Values(true, false)] bool throwOnUnnasignedFrameDeserialization, [Values(null, 10)] int?hintAvgFrameSize)
        {
            TestOuterContainer   ocOriginal        = SampleCreator.GetOuterContainerSample(sampleType);
            FrameParallelOptions mpOptionsParallel = GetOptionsParallel(totThreads, throwOnUnnasignedFrameDeserialization, hintAvgFrameSize);

            byte[] msgpackBytes = MessagePackSerializer.Serialize(ocOriginal, mpOptionsParallel);

            TestOuterContainer ocFinal = MessagePackSerializer.Deserialize <TestOuterContainer>(msgpackBytes, mpOptionsParallel);

            Assert.AreEqual(ocOriginal, ocFinal);
        }