public async Task <InputFormatterResult> ReadAsync(InputFormatterContext context) { var request = context.HttpContext.Request; var result = await MessagePackSerializer.DeserializeAsync(context.ModelType, request.Body, options); return(await InputFormatterResult.SuccessAsync(result)); }
public static async Task <ArrayX> Original_KnownLengthArray_ReadAsync(string fileName) { var opts = MessagePackSerializerOptions.Standard; using var stream = File.OpenRead(fileName); return(await MessagePackSerializer.DeserializeAsync <ArrayX>(stream, opts)); }
public override async Task <InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context) { try { MemoryStream memoryStream = new MemoryStream(); await context.HttpContext.Request.Body.CopyToAsync(memoryStream).ConfigureAwait(false); memoryStream.Seek(0, SeekOrigin.Begin); if (memoryStream.Length == 0) { return(InputFormatterResult.NoValue()); } object model = await MessagePackSerializer .DeserializeAsync(context.ModelType, memoryStream) .ConfigureAwait(false); return(InputFormatterResult.Success(model)); } catch (Exception) { //TODO : Log return(InputFormatterResult.Failure()); } }
public async Task <int> ReadAsync_Baseline(BufferedStreamReaderConfig config_r, bool usingMemoryStream) { if (!usingMemoryStream) { FileHelper.FlushFileCache(tmpFilename_baseline); } try { using (StreamChain sc1 = new StreamChain()) { Stream s = sc1.ComposeChain( usingMemoryStream ? ms_baseline : File.Open(tmpFilename_baseline, FileMode.Open, FileAccess.Read, FileShare.None), config_r); var obj = await MessagePackSerializer.DeserializeAsync <T_Baseline>(s, opts_standard); return(obj.DoStuff()); } } finally { if (usingMemoryStream) { ms_baseline.Flush(); ms_baseline.Position = 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 async Task <T> DeserializeFromStreamAsync <T>(Stream input, CancellationToken cancellationToken = default) { return(await MessagePackSerializer.DeserializeAsync <T>( input, options : MessagePack.Resolvers.ContractlessStandardResolverAllowPrivate.Options, cancellationToken : cancellationToken)); }
public override async Task <InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context) { var body = context.HttpContext.Request.Body; var result = await MessagePackSerializer.DeserializeAsync(context.ModelType, body, _options); return(await InputFormatterResult.SuccessAsync(result)); }
public async Task <InputFormatterResult> ReadAsync(InputFormatterContext context) { Microsoft.AspNetCore.Http.HttpRequest request = context.HttpContext.Request; object result = await MessagePackSerializer.DeserializeAsync(context.ModelType, request.Body, this.options, context.HttpContext.RequestAborted); return(await InputFormatterResult.SuccessAsync(result)); }
private static async Task <ClaimsPrincipal> DeserializePrincipal(Stream stream) { var messagePrincipal = await MessagePackSerializer.DeserializeAsync <MessagePrincipal>(stream); return(messagePrincipal.ToClaimsPrincipal()); }
public override async Task <T> DeserializeAsync <T>(ArraySegment <byte> rawBytes, Session context) { using (var memory = new MemoryStream(rawBytes.ToArray())) { return(await MessagePackSerializer.DeserializeAsync <T>(memory, _options)); } }
public async Task <InputFormatterResult> ReadAsync(InputFormatterContext context) { var request = context.HttpContext.Request; var result = await MessagePackSerializer.DeserializeAsync(context.ModelType, request.Body, this.options, context.HttpContext.RequestAborted).ConfigureAwait(false); return(await InputFormatterResult.SuccessAsync(result).ConfigureAwait(false)); }
private static Task <T> DeserializeAsync <T>(byte[] buf) { using (var stream = new System.IO.MemoryStream(buf)) { return(MessagePackSerializer.DeserializeAsync <T>(stream)); } }
public async Task Deserialize() { FileStream fs = null; GeneratorData data = null; deserializing = true; var sw = System.Diagnostics.Stopwatch.StartNew(); try { if (Application.platform == RuntimePlatform.Android) { UnityWebRequest www = new UnityWebRequest(Application.streamingAssetsPath + "/" + SceneManager.GetActiveScene().name + "_" + gameObject.name + ".nodes") { downloadHandler = new DownloadHandlerBuffer() }; www.SendWebRequest(); while (!www.isDone) { await Task.Delay(10); } data = MessagePackSerializer.Deserialize <GeneratorData>(www.downloadHandler.data, options); } else { fs = new FileStream(Application.streamingAssetsPath + "/" + SceneManager.GetActiveScene().name + "_" + gameObject.name + ".nodes", FileMode.Open, FileAccess.Read, FileShare.None, 128000); data = await Task.Run(() => MessagePackSerializer.DeserializeAsync <GeneratorData>(fs, options)).Result; //data = MessagePackSerializer.Deserialize<GeneratorData>(fs, options); } } catch { //print(e); } finally { fs?.Close(); deserializing = false; if (data != null) { print("Loaded, " + sw.Elapsed.TotalSeconds + "s"); sw.Restart(); for (int i = 0; i < data.chunkData.Length; i++) { chunks[i].Deserialize(data.chunkData[i]); } if (pathfindingType != PathfindingType.navmeshOnly) { MarchCubes(); } AssignNeighbours(); print("Init, " + sw.Elapsed.TotalSeconds); sw.Stop(); OnInitialize?.Invoke(); } } }
/// <summary> /// ストリームからMessagePackデータをデシリアライズする /// </summary> /// <typeparam name="T">型</typeparam> /// <param name="stream">ストリーム</param> /// <returns>Task<typeparamref name="T"/></returns> public static async Task <T> DeserializeAsync <T>(Stream stream) { var @object = await MessagePackSerializer .DeserializeAsync <T>(stream, _options) .ConfigureAwait(false); return(@object); }
public ValueTask <SnapAppsReleases> BuildSnapAppsReleasesFromStreamAsync([NotNull] MemoryStream stream) { if (stream == null) { throw new ArgumentNullException(nameof(stream)); } return(MessagePackSerializer.DeserializeAsync <SnapAppsReleases>(stream, MessagePackSerializerOptions.Standard.WithCompression(MessagePackCompression.Lz4BlockArray))); }
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)); }
/// <inheritdoc /> public override async Task <InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context) { var httpContext = context.HttpContext; var result = await MessagePackSerializer.DeserializeAsync(context.ModelType, httpContext.Request.Body, _options, httpContext.RequestAborted).ConfigureAwait(false); // ReSharper disable once MethodHasAsyncOverload return(InputFormatterResult.Success(result)); }
private async Task <DiskCacheValue> GetDiskCacheValueAsync(string path) { using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { var cached = await MessagePackSerializer.DeserializeAsync <DiskCacheValue>(stream, MessagePackSerializerOptions.Standard.WithResolver(ContractlessStandardResolver.Instance)); return(cached); } }
private async Task <DiskCacheValue> GetDiskCacheValueAsync(string path) { using (FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { var cached = await MessagePackSerializer.DeserializeAsync <DiskCacheValue>(stream); return(cached); } }
private async Task <T> Deserizlize <T>(byte[] bytes) { using (MemoryStream memoryStream = new MemoryStream(bytes)) { var options = ContractlessStandardResolver.Options; options = options.WithCompression(MessagePackCompression.Lz4Block); return(await MessagePackSerializer.DeserializeAsync <T>(memoryStream, options)); } }
public static async ValueTask <IApiResponse <T> > DeserializeAsync <T>( Stream stream, CancellationToken cancellationToken) { var type = GetDeserializeType <T>(); var obj = await MessagePackSerializer.DeserializeAsync( type, stream, options : Serializable.lz4Options, cancellationToken : cancellationToken); return((IApiResponse <T>?)obj ?? ClientDeserializeFail <T>()); }
public async Task ReadAsStreamArrayAsync_NullObject_Test() { var content = MessagePackContent.Create <SimpleType>(null, _options, _mediaType); await using var stream = await content.ReadAsStreamAsync(); var model = await MessagePackSerializer.DeserializeAsync <SimpleType>(stream, _options); Assert.Null(model); }
public async Task ReadAsStreamArrayAsync_Test() { var inputValue = SimpleType.Create(); var content = MessagePackContent.Create(inputValue, _options, _mediaType); await using var stream = await content.ReadAsStreamAsync(); var model = await MessagePackSerializer.DeserializeAsync <SimpleType>(stream, _options); model.Verify(); }
public override async Task <object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (readStream == null) { throw new ArgumentNullException(nameof(readStream)); } return(await MessagePackSerializer.DeserializeAsync(type, readStream, _options)); }
public async Task Contractless_Serialize_And_Deserialize_string_Stream_TestAsync() { var testObject = "test"; var stream = new MemoryStream(); await MessagePackSerializer.SerializeAsync(typeof(string), stream, testObject, _contractlessOptions, default).ConfigureAwait(false); stream.Position = 0; var deserialized = await MessagePackSerializer.DeserializeAsync <string>(stream, _contractlessOptions, default).ConfigureAwait(false); Assert.True(deserialized.Equals(testObject)); }
public async Task CopyToAsync_NullObject_Test() { var content = MessagePackContent.Create <SimpleType>(null, _options, _mediaType); await using var stream = new MemoryStream(); await content.CopyToAsync(stream); stream.Position = 0; var model = await MessagePackSerializer.DeserializeAsync <SimpleType>(stream, _options); Assert.Null(model); }
public async Task NonGeneric_Async() { var data = new FirstSimpleData { Prop1 = 9, Prop2 = "hoge", Prop3 = 999 }; Type t = typeof(FirstSimpleData); var ms = new MemoryStream(); await MessagePackSerializer.SerializeAsync(t, ms, data); ms.Position = 0; var data2 = (FirstSimpleData)await MessagePackSerializer.DeserializeAsync(t, ms); Assert.Equal(data, data2); }
public async Task SerializeAndDeserializeAsync_MultipleValues_NonSeekableStream() { var ms = new MemoryStream(); Stream stream = new StreamWrapper(ms, canSeek: false); await MessagePackSerializer.SerializeAsync(stream, 1); await MessagePackSerializer.SerializeAsync(stream, 2); ms.Position = 0; Assert.Equal(1, await MessagePackSerializer.DeserializeAsync <int>(stream)); var ex = await Assert.ThrowsAsync <MessagePackSerializationException>(async() => await MessagePackSerializer.DeserializeAsync <int>(stream)); Assert.IsType <EndOfStreamException>(ex.InnerException); }
private async ValueTask <Settings> LoadSettings() { if (File.Exists(SettingFilePath)) { using (var fstream = File.OpenRead(SettingFilePath)) { if (fstream.Length > 0) { return(await MessagePackSerializer.DeserializeAsync <Settings>(fstream, JsonResolver)); } } } return(new Settings()); }
public async Task CopyToAsync_Test() { var inputValue = SimpleType.Create(); var content = MessagePackContent.Create(inputValue, _options, _mediaType); await using var stream = new MemoryStream(); await content.CopyToAsync(stream); stream.Position = 0; var model = await MessagePackSerializer.DeserializeAsync <SimpleType>(stream, _options); model.Verify(); }