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; } } }
private FrameParallelOptions GetOptionsParallel(int totThreads, bool throwOnUnnasignedFrameDeserialization, int?hintAvgFrameSize) { return(new FrameParallelOptions(new FrameFormatterSerializationOptions( new BatchSizeEstimatorConfig(hintAvgFrameSize_bytes: hintAvgFrameSize), new FIFOWorkerConfig(maxConcurrentTasks: totThreads), new MultiThreadedWorkerConfig(totThreads: totThreads), throwOnUnnasignedFrameDeserialization: throwOnUnnasignedFrameDeserialization), mpOptionsSerial.WithResolver(FrameResolverPlusStandarResolver.Instance))); }
public void WithResolver_PreservesOtherProperties() { var mutated = NonDefaultOptions.WithResolver(ContractlessStandardResolver.Instance); Assert.Same((object)ContractlessStandardResolver.Instance, (object)mutated.Resolver); Assert.Equal(NonDefaultOptions.Compression, mutated.Compression); Assert.Equal(NonDefaultOptions.OldSpec, mutated.OldSpec); Assert.Equal(NonDefaultOptions.AllowAssemblyVersionMismatch, mutated.AllowAssemblyVersionMismatch); Assert.Equal(NonDefaultOptions.OmitAssemblyVersion, mutated.OmitAssemblyVersion); }
private void SetupResolver(MessagePackHubProtocolOptions options) { _options = MessagePackSerializerOptions.Standard; // if counts don't match then we know users customized resolvers so we set up the options // with the provided resolvers if (options.FormatterResolvers.Count != SignalRResolver.Resolvers.Count) { _options = _options.WithResolver(new CombinedResolvers(options.FormatterResolvers)); return; } for (var i = 0; i < options.FormatterResolvers.Count; i++) { // check if the user customized the resolvers if (options.FormatterResolvers[i] != SignalRResolver.Resolvers[i]) { _options = _options.WithResolver(new CombinedResolvers(options.FormatterResolvers)); return; } } // Use optimized cached resolver if the default is chosen _options.WithResolver(SignalRResolver.Instance); }
public async Task <ArgumentDictionary> DeserializeArgumentsAsync(Stream stream, Dictionary <string, Type> argumentMapping) { return(await MessagePackSerializer.DeserializeAsync <ArgumentDictionary>(stream, options.WithResolver(new ArgumentDictionaryFormatterResolver(argumentMapping)))); }
private T Convert <T>(T value) { MessagePackSerializerOptions options = LZ4Standard.WithResolver(new WithImmutableDefaultResolver()); return(MessagePackSerializer.Deserialize <T>(MessagePackSerializer.Serialize(value, options), options)); }