/// <summary> /// <para>异步的从指定的<paramref name="stream"/>反序列化给定类型的值</para> /// <para>Asynchronously deserializes the value of the given type from the specified <paramref name="stream"/></para> /// </summary> /// <param name="stream">反序列化所需要的的流. The stream to deserialize from</param> /// <param name="option">使用的配置,如果为<c>null</c>,则使用默认配置. The options. Use <c>null</c> to use default options</param> /// <param name="cancellationToken">取消该操作的令牌. The token to cancel the operation</param> /// <returns>反序列化的值. The deserialized value</returns> public static async Task <T> DeserializeAsync <T>(Stream stream, BssomSerializerOptions option = null, CancellationToken cancellationToken = default) { BssomDeserializeContext context = new BssomDeserializeContext(option, cancellationToken); if (TryDeserializeFromMemoryStream <T>(ref context, stream, out T result)) { return(result); } StreamDeserializeAux aux = new StreamDeserializeAux(stream); IBssomBuffer bssomBuf = await aux.GetBssomBufferAsync().ConfigureAwait(false); result = Deserialize <T>(ref context, bssomBuf); aux.Dispose(); return(result); }
/// <summary> /// <para>异步的从指定的<paramref name="stream"/>反序列化给定类型的值</para> /// <para>Asynchronously deserializes the value of the given type from the specified <paramref name="stream"/></para> /// </summary> /// <param name="stream">反序列化所需要的的流. The stream to deserialize from</param> /// <param name="type">要反序列化的类型. The type to deserialize</param> /// <param name="option">使用的配置,如果为<c>null</c>,则使用默认配置. The options. Use <c>null</c> to use default options</param> /// <param name="cancellationToken">取消该操作的令牌. The token to cancel the operation</param> /// <returns>反序列化的值. The deserialized value</returns> public static async Task <object> DeserializeAsync(Stream stream, Type type, BssomSerializerOptions option = null, CancellationToken cancellationToken = default) { if (type == null) { throw new ArgumentNullException(nameof(type)); } BssomDeserializeContext context = new BssomDeserializeContext(option, cancellationToken); if (TryDeserializeFromMemoryStream(ref context, stream, out object result)) { return(result); } StreamDeserializeAux aux = new StreamDeserializeAux(stream); IBssomBuffer bssomBuf = await aux.GetBssomBufferAsync().ConfigureAwait(false); result = Deserialize(ref context, bssomBuf, type); aux.Dispose(); return(result); }