/// <summary> /// Decodes a CloudEvent from a structured-mode message body, represented as a stream. The default implementation asynchronously copies the /// content of the stream into a byte array before passing it to <see cref="DecodeStructuredModeMessage(byte[], ContentType, IEnumerable{CloudEventAttribute})"/> /// but this can be overridden by event formatters that can decode a stream more efficiently. /// </summary> /// <param name="data">The data within the message body. Must not be null.</param> /// <param name="contentType">The content type of the message, or null if no content type is known. /// Typically this is a content type with a media type of "application/cloudevents"; the additional /// information such as the charset parameter may be needed in order to decode the data.</param> /// <param name="extensions">The extension attributes to use when populating the CloudEvent. May be null.</param> /// <returns>The CloudEvent derived from the structured data.</returns> public virtual async Task <CloudEvent> DecodeStructuredModeMessageAsync(Stream data, ContentType contentType, IEnumerable <CloudEventAttribute> extensionAttributes) { var bytes = await BinaryDataUtilities.ToByteArrayAsync(data).ConfigureAwait(false); return(DecodeStructuredModeMessage(bytes, contentType, extensionAttributes)); }
/// <summary> /// Asynchronously decodes a collection CloudEvents from a batch-mode message body, represented as a stream. The default implementation asynchronously copies the /// content of the stream into a byte array before passing it to <see cref="DecodeBatchModeMessage(byte[], ContentType, IEnumerable{CloudEventAttribute})"/> /// but this can be overridden by event formatters that can decode a stream more efficiently. /// </summary> /// <param name="body">The message body (content). Must not be null.</param> /// <param name="contentType">The content type of the message, or null if no content type is known. /// Typically this is a content type with a media type with a prefix of "application/cloudevents"; the additional /// information such as the charset parameter may be needed in order to decode the message body.</param> /// <param name="extensionAttributes">The extension attributes to use when populating the CloudEvent. May be null.</param> /// <returns>The collection of CloudEvents derived from the batch message body.</returns> public virtual async Task <IReadOnlyList <CloudEvent> > DecodeBatchModeMessageAsync(Stream body, ContentType contentType, IEnumerable <CloudEventAttribute> extensionAttributes) { var bytes = await BinaryDataUtilities.ToByteArrayAsync(body).ConfigureAwait(false); return(DecodeBatchModeMessage(bytes, contentType, extensionAttributes)); }