/// <summary> /// Bond-serializes a given <typeparamref name="T"/> and stores the result to the content cache. /// The returned content hash can be used to later deserialize the structure with <see cref="TryLoadAndDeserializeContent{T}"/>. /// </summary> public static Task <Possible <ContentHash> > TrySerializeAndStoreContent <T>( this IArtifactContentCache contentCache, T valueToSerialize, BoxRef <long> contentSize = null, StoreArtifactOptions options = default) { return(BondExtensions.TrySerializeAndStoreContent( valueToSerialize, async(valueHash, valueBuffer) => { using (var entryStream = new MemoryStream( valueBuffer.Array, valueBuffer.Offset, valueBuffer.Count, writable: false)) { Possible <Unit, Failure> maybeStored = await contentCache.TryStoreAsync( entryStream, contentHash: valueHash, options: options); return maybeStored.WithGenericFailure(); } }, contentSize)); }
/// <summary> /// Bond-serializes a given <typeparamref name="T"/> and stores the result to the content cache. /// The returned content hash can be used to later deserialize the structure with <see cref="TryLoadAndDeserializeContent{T}"/>. /// </summary> public static Task <Possible <ContentHash> > TrySerializeAndStoreContent <T>( this IArtifactContentCache contentCache, T valueToSerialize, BoxRef <long> contentSize = null) { return(BondExtensions.TrySerializeAndStoreContent( contentCache, valueToSerialize, TryStoreContentAsync, contentSize)); }