/// <summary> /// Decodes a CloudEvent from a structured-mode message body, represented as a stream. The default implementation copies the /// content of the stream into a read-only memory segment before passing it to <see cref="DecodeStructuredModeMessage(ReadOnlyMemory{byte}, ContentType, IEnumerable{CloudEventAttribute})"/> /// but this can be overridden by event formatters that can decode a stream more efficiently. /// </summary> /// <param name="messageBody">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 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 decoded CloudEvent.</returns> public virtual CloudEvent DecodeStructuredModeMessage(Stream messageBody, ContentType?contentType, IEnumerable <CloudEventAttribute>?extensionAttributes) { var bytes = BinaryDataUtilities.ToReadOnlyMemory(messageBody); return(DecodeStructuredModeMessage(bytes, contentType, extensionAttributes)); }
/// <summary> /// Decodes a collection CloudEvents from a batch-mode message body, represented as a stream. The default implementation copies the /// content of the stream into a read-only memory segment before passing it to <see cref="DecodeBatchModeMessage(ReadOnlyMemory{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 IReadOnlyList <CloudEvent> DecodeBatchModeMessage(Stream body, ContentType?contentType, IEnumerable <CloudEventAttribute>?extensionAttributes) { var bytes = BinaryDataUtilities.ToReadOnlyMemory(body); return(DecodeBatchModeMessage(bytes, contentType, extensionAttributes)); }