Rename ICloudEventFormatter to CloudEventFormatter
While this could be CloudEventFormatterBase, it's probably clearer as it is. Signed-off-by: Jon Skeet <jonskeet@google.com>
This commit is contained in:
parent
c3495d0a55
commit
52437b3d50
|
@ -20,7 +20,7 @@ namespace CloudNative.CloudEvents.Amqp
|
||||||
message.ApplicationProperties.Map.ContainsKey(SpecVersionAmqpHeader);
|
message.ApplicationProperties.Map.ContainsKey(SpecVersionAmqpHeader);
|
||||||
|
|
||||||
public static CloudEvent ToCloudEvent(this Message message,
|
public static CloudEvent ToCloudEvent(this Message message,
|
||||||
ICloudEventFormatter formatter,
|
CloudEventFormatter formatter,
|
||||||
params CloudEventAttribute[] extensionAttributes)
|
params CloudEventAttribute[] extensionAttributes)
|
||||||
{
|
{
|
||||||
if (HasCloudEventsContentType(message))
|
if (HasCloudEventsContentType(message))
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace CloudNative.CloudEvents.Amqp
|
||||||
{
|
{
|
||||||
public class AmqpCloudEventMessage : Message
|
public class AmqpCloudEventMessage : Message
|
||||||
{
|
{
|
||||||
public AmqpCloudEventMessage(CloudEvent cloudEvent, ContentMode contentMode, ICloudEventFormatter formatter)
|
public AmqpCloudEventMessage(CloudEvent cloudEvent, ContentMode contentMode, CloudEventFormatter formatter)
|
||||||
{
|
{
|
||||||
ApplicationProperties = new ApplicationProperties();
|
ApplicationProperties = new ApplicationProperties();
|
||||||
MapHeaders(cloudEvent);
|
MapHeaders(cloudEvent);
|
||||||
|
|
|
@ -16,9 +16,9 @@ namespace CloudNative.CloudEvents
|
||||||
|
|
||||||
public class CloudEventJsonInputFormatter : TextInputFormatter
|
public class CloudEventJsonInputFormatter : TextInputFormatter
|
||||||
{
|
{
|
||||||
private readonly ICloudEventFormatter _formatter;
|
private readonly CloudEventFormatter _formatter;
|
||||||
|
|
||||||
public CloudEventJsonInputFormatter(ICloudEventFormatter formatter)
|
public CloudEventJsonInputFormatter(CloudEventFormatter formatter)
|
||||||
{
|
{
|
||||||
_formatter = formatter;
|
_formatter = formatter;
|
||||||
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/json"));
|
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/json"));
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace CloudNative.CloudEvents
|
||||||
/// <param name="extensions">List of extension instances</param>
|
/// <param name="extensions">List of extension instances</param>
|
||||||
/// <returns>A CloudEvent instance or 'null' if the request message doesn't hold a CloudEvent</returns>
|
/// <returns>A CloudEvent instance or 'null' if the request message doesn't hold a CloudEvent</returns>
|
||||||
public static async ValueTask<CloudEvent> ReadCloudEventAsync(this HttpRequest httpRequest,
|
public static async ValueTask<CloudEvent> ReadCloudEventAsync(this HttpRequest httpRequest,
|
||||||
ICloudEventFormatter formatter,
|
CloudEventFormatter formatter,
|
||||||
params CloudEventAttribute[] extensionAttributes)
|
params CloudEventAttribute[] extensionAttributes)
|
||||||
{
|
{
|
||||||
if (HasCloudEventsContentType(httpRequest))
|
if (HasCloudEventsContentType(httpRequest))
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace CloudNative.CloudEvents
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Formatter that implements the Avro Event Format
|
/// Formatter that implements the Avro Event Format
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AvroEventFormatter : ICloudEventFormatter
|
public class AvroEventFormatter : CloudEventFormatter
|
||||||
{
|
{
|
||||||
private const string DataName = "data";
|
private const string DataName = "data";
|
||||||
private static readonly RecordSchema avroSchema;
|
private static readonly RecordSchema avroSchema;
|
||||||
|
|
|
@ -20,11 +20,11 @@ namespace CloudNative.CloudEvents.Kafka
|
||||||
(ExtractContentType(message)?.StartsWith(CloudEvent.MediaType, StringComparison.InvariantCultureIgnoreCase) == true);
|
(ExtractContentType(message)?.StartsWith(CloudEvent.MediaType, StringComparison.InvariantCultureIgnoreCase) == true);
|
||||||
|
|
||||||
public static CloudEvent ToCloudEvent(this Message<string, byte[]> message,
|
public static CloudEvent ToCloudEvent(this Message<string, byte[]> message,
|
||||||
ICloudEventFormatter eventFormatter, params CloudEventAttribute[] extensionAttributes) =>
|
CloudEventFormatter eventFormatter, params CloudEventAttribute[] extensionAttributes) =>
|
||||||
ToCloudEvent(message, eventFormatter, (IEnumerable<CloudEventAttribute>) extensionAttributes);
|
ToCloudEvent(message, eventFormatter, (IEnumerable<CloudEventAttribute>) extensionAttributes);
|
||||||
|
|
||||||
public static CloudEvent ToCloudEvent(this Message<string, byte[]> message,
|
public static CloudEvent ToCloudEvent(this Message<string, byte[]> message,
|
||||||
ICloudEventFormatter eventFormatter, IEnumerable<CloudEventAttribute> extensionAttributes)
|
CloudEventFormatter eventFormatter, IEnumerable<CloudEventAttribute> extensionAttributes)
|
||||||
{
|
{
|
||||||
if (!IsCloudEvent(message))
|
if (!IsCloudEvent(message))
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace CloudNative.CloudEvents.Kafka
|
||||||
internal const string KafkaContentTypeAttributeName = "content-type";
|
internal const string KafkaContentTypeAttributeName = "content-type";
|
||||||
internal const string SpecVersionKafkaHeader = KafkaHeaderPrefix + "specversion";
|
internal const string SpecVersionKafkaHeader = KafkaHeaderPrefix + "specversion";
|
||||||
|
|
||||||
public KafkaCloudEventMessage(CloudEvent cloudEvent, ContentMode contentMode, ICloudEventFormatter formatter)
|
public KafkaCloudEventMessage(CloudEvent cloudEvent, ContentMode contentMode, CloudEventFormatter formatter)
|
||||||
{
|
{
|
||||||
// TODO: Is this appropriate? Why can't we transport a CloudEvent without data in Kafka?
|
// TODO: Is this appropriate? Why can't we transport a CloudEvent without data in Kafka?
|
||||||
if (cloudEvent.Data == null)
|
if (cloudEvent.Data == null)
|
||||||
|
@ -70,7 +70,7 @@ namespace CloudNative.CloudEvents.Kafka
|
||||||
MapHeaders(cloudEvent, formatter);
|
MapHeaders(cloudEvent, formatter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MapHeaders(CloudEvent cloudEvent, ICloudEventFormatter formatter)
|
private void MapHeaders(CloudEvent cloudEvent, CloudEventFormatter formatter)
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach (var pair in cloudEvent.GetPopulatedAttributes())
|
foreach (var pair in cloudEvent.GetPopulatedAttributes())
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace CloudNative.CloudEvents.Mqtt
|
||||||
public static class MqttClientExtensions
|
public static class MqttClientExtensions
|
||||||
{
|
{
|
||||||
public static CloudEvent ToCloudEvent(this MqttApplicationMessage message,
|
public static CloudEvent ToCloudEvent(this MqttApplicationMessage message,
|
||||||
ICloudEventFormatter eventFormatter, params CloudEventAttribute[] extensionAttributes)
|
CloudEventFormatter eventFormatter, params CloudEventAttribute[] extensionAttributes)
|
||||||
{
|
{
|
||||||
return eventFormatter.DecodeStructuredEvent(message.Payload, extensionAttributes);
|
return eventFormatter.DecodeStructuredEvent(message.Payload, extensionAttributes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace CloudNative.CloudEvents.Mqtt
|
||||||
// TODO: Update to a newer version of MQTTNet and support both binary and structured mode?
|
// TODO: Update to a newer version of MQTTNet and support both binary and structured mode?
|
||||||
public class MqttCloudEventMessage : MqttApplicationMessage
|
public class MqttCloudEventMessage : MqttApplicationMessage
|
||||||
{
|
{
|
||||||
public MqttCloudEventMessage(CloudEvent cloudEvent, ICloudEventFormatter formatter)
|
public MqttCloudEventMessage(CloudEvent cloudEvent, CloudEventFormatter formatter)
|
||||||
{
|
{
|
||||||
this.Payload = formatter.EncodeStructuredEvent(cloudEvent, out var contentType);
|
this.Payload = formatter.EncodeStructuredEvent(cloudEvent, out var contentType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Formatter that implements the JSON Event Format
|
/// Formatter that implements the JSON Event Format
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class JsonEventFormatter : ICloudEventFormatter
|
public class JsonEventFormatter : CloudEventFormatter
|
||||||
{
|
{
|
||||||
private const string DataBase64 = "data_base64";
|
private const string DataBase64 = "data_base64";
|
||||||
private const string Data = "data";
|
private const string Data = "data";
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace CloudNative.CloudEvents
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implemented by formatters
|
/// Implemented by formatters
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class ICloudEventFormatter
|
public abstract class CloudEventFormatter
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Decode a structured event from a stream
|
/// Decode a structured event from a stream
|
|
@ -26,7 +26,7 @@ namespace CloudNative.CloudEvents.Http
|
||||||
/// <param name="cloudEvent">CloudEvent</param>
|
/// <param name="cloudEvent">CloudEvent</param>
|
||||||
/// <param name="contentMode">Content mode. Structured or binary.</param>
|
/// <param name="contentMode">Content mode. Structured or binary.</param>
|
||||||
/// <param name="formatter">Event formatter</param>
|
/// <param name="formatter">Event formatter</param>
|
||||||
public CloudEventHttpContent(CloudEvent cloudEvent, ContentMode contentMode, ICloudEventFormatter formatter)
|
public CloudEventHttpContent(CloudEvent cloudEvent, ContentMode contentMode, CloudEventFormatter formatter)
|
||||||
{
|
{
|
||||||
if (contentMode == ContentMode.Structured)
|
if (contentMode == ContentMode.Structured)
|
||||||
{
|
{
|
||||||
|
|
|
@ -80,7 +80,7 @@ namespace CloudNative.CloudEvents.Http
|
||||||
/// <param name="extensionAttributes">The extension attributes to use when parsing the CloudEvent.</param>
|
/// <param name="extensionAttributes">The extension attributes to use when parsing the CloudEvent.</param>
|
||||||
/// <returns>A CloudEvent instance or 'null' if the response message doesn't hold a CloudEvent</returns>
|
/// <returns>A CloudEvent instance or 'null' if the response message doesn't hold a CloudEvent</returns>
|
||||||
public static Task<CloudEvent> ToCloudEventAsync(this HttpResponseMessage httpResponseMessage,
|
public static Task<CloudEvent> ToCloudEventAsync(this HttpResponseMessage httpResponseMessage,
|
||||||
ICloudEventFormatter formatter, params CloudEventAttribute[] extensionAttributes) =>
|
CloudEventFormatter formatter, params CloudEventAttribute[] extensionAttributes) =>
|
||||||
ToCloudEventInternalAsync(httpResponseMessage.Headers, httpResponseMessage.Content, formatter, extensionAttributes);
|
ToCloudEventInternalAsync(httpResponseMessage.Headers, httpResponseMessage.Content, formatter, extensionAttributes);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -91,12 +91,12 @@ namespace CloudNative.CloudEvents.Http
|
||||||
/// <param name="extensionAttributes">List of extension instances</param>
|
/// <param name="extensionAttributes">List of extension instances</param>
|
||||||
/// <returns>A CloudEvent instance or 'null' if the request message doesn't hold a CloudEvent</returns>
|
/// <returns>A CloudEvent instance or 'null' if the request message doesn't hold a CloudEvent</returns>
|
||||||
public static Task<CloudEvent> ToCloudEventAsync(this HttpRequestMessage httpRequestMessage,
|
public static Task<CloudEvent> ToCloudEventAsync(this HttpRequestMessage httpRequestMessage,
|
||||||
ICloudEventFormatter formatter,
|
CloudEventFormatter formatter,
|
||||||
params CloudEventAttribute[] extensionAttributes) =>
|
params CloudEventAttribute[] extensionAttributes) =>
|
||||||
ToCloudEventInternalAsync(httpRequestMessage.Headers, httpRequestMessage.Content, formatter, extensionAttributes);
|
ToCloudEventInternalAsync(httpRequestMessage.Headers, httpRequestMessage.Content, formatter, extensionAttributes);
|
||||||
|
|
||||||
private static async Task<CloudEvent> ToCloudEventInternalAsync(HttpHeaders headers, HttpContent content,
|
private static async Task<CloudEvent> ToCloudEventInternalAsync(HttpHeaders headers, HttpContent content,
|
||||||
ICloudEventFormatter formatter, IEnumerable<CloudEventAttribute> extensionAttributes)
|
CloudEventFormatter formatter, IEnumerable<CloudEventAttribute> extensionAttributes)
|
||||||
{
|
{
|
||||||
if (HasCloudEventsContentType(content))
|
if (HasCloudEventsContentType(content))
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace CloudNative.CloudEvents.Http
|
||||||
/// <param name="formatter">Formatter</param>
|
/// <param name="formatter">Formatter</param>
|
||||||
/// <returns>Task</returns>
|
/// <returns>Task</returns>
|
||||||
public static Task CopyFromAsync(this HttpListenerResponse httpListenerResponse, CloudEvent cloudEvent,
|
public static Task CopyFromAsync(this HttpListenerResponse httpListenerResponse, CloudEvent cloudEvent,
|
||||||
ContentMode contentMode, ICloudEventFormatter formatter)
|
ContentMode contentMode, CloudEventFormatter formatter)
|
||||||
{
|
{
|
||||||
if (contentMode == ContentMode.Structured)
|
if (contentMode == ContentMode.Structured)
|
||||||
{
|
{
|
||||||
|
@ -99,7 +99,7 @@ namespace CloudNative.CloudEvents.Http
|
||||||
/// <param name="extensions">List of extension instances</param>
|
/// <param name="extensions">List of extension instances</param>
|
||||||
/// <returns>A CloudEvent instance or 'null' if the request message doesn't hold a CloudEvent</returns>
|
/// <returns>A CloudEvent instance or 'null' if the request message doesn't hold a CloudEvent</returns>
|
||||||
public static CloudEvent ToCloudEvent(this HttpListenerRequest httpListenerRequest,
|
public static CloudEvent ToCloudEvent(this HttpListenerRequest httpListenerRequest,
|
||||||
ICloudEventFormatter formatter, params CloudEventAttribute[] extensionAttributes)
|
CloudEventFormatter formatter, params CloudEventAttribute[] extensionAttributes)
|
||||||
{
|
{
|
||||||
if (HasCloudEventsContentType(httpListenerRequest))
|
if (HasCloudEventsContentType(httpListenerRequest))
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace CloudNative.CloudEvents.Http
|
||||||
|
|
||||||
public const string SpecVersionHttpHeader = HttpHeaderPrefix + "specversion";
|
public const string SpecVersionHttpHeader = HttpHeaderPrefix + "specversion";
|
||||||
|
|
||||||
internal static Stream MapDataAttributeToStream(CloudEvent cloudEvent, ICloudEventFormatter formatter) =>
|
internal static Stream MapDataAttributeToStream(CloudEvent cloudEvent, CloudEventFormatter formatter) =>
|
||||||
cloudEvent.Data switch
|
cloudEvent.Data switch
|
||||||
{
|
{
|
||||||
byte[] bytes => new MemoryStream(bytes),
|
byte[] bytes => new MemoryStream(bytes),
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace CloudNative.CloudEvents.Http
|
||||||
/// <param name="formatter">Formatter</param>
|
/// <param name="formatter">Formatter</param>
|
||||||
/// <returns>Task</returns>
|
/// <returns>Task</returns>
|
||||||
public static async Task CopyFromAsync(this HttpWebRequest httpWebRequest, CloudEvent cloudEvent,
|
public static async Task CopyFromAsync(this HttpWebRequest httpWebRequest, CloudEvent cloudEvent,
|
||||||
ContentMode contentMode, ICloudEventFormatter formatter)
|
ContentMode contentMode, CloudEventFormatter formatter)
|
||||||
{
|
{
|
||||||
if (contentMode == ContentMode.Structured)
|
if (contentMode == ContentMode.Structured)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue