Change ICloudEventFormatter into an abstract class
Obviously the name is then inappropriate, but that will be changed in a subsequent commit. Signed-off-by: Jon Skeet <jonskeet@google.com>
This commit is contained in:
parent
8b63348296
commit
c3495d0a55
|
@ -40,10 +40,10 @@ namespace CloudNative.CloudEvents
|
|||
DecodeStructuredEvent(data, (IEnumerable<CloudEventAttribute>)extensionAttributes);
|
||||
|
||||
// FIXME: We shouldn't use synchronous stream methods...
|
||||
public Task<CloudEvent> DecodeStructuredEventAsync(Stream data, IEnumerable<CloudEventAttribute> extensionAttributes) =>
|
||||
public override Task<CloudEvent> DecodeStructuredEventAsync(Stream data, IEnumerable<CloudEventAttribute> extensionAttributes) =>
|
||||
Task.FromResult(DecodeStructuredEvent(data, extensionAttributes));
|
||||
|
||||
public CloudEvent DecodeStructuredEvent(Stream data, IEnumerable<CloudEventAttribute> extensionAttributes)
|
||||
public override CloudEvent DecodeStructuredEvent(Stream data, IEnumerable<CloudEventAttribute> extensionAttributes)
|
||||
{
|
||||
var decoder = new Avro.IO.BinaryDecoder(data);
|
||||
var rawEvent = avroReader.Read<GenericRecord>(null, decoder);
|
||||
|
@ -53,7 +53,7 @@ namespace CloudNative.CloudEvents
|
|||
public CloudEvent DecodeStructuredEvent(byte[] data, params CloudEventAttribute[] extensionAttributes) =>
|
||||
DecodeStructuredEvent(data, (IEnumerable<CloudEventAttribute>) extensionAttributes);
|
||||
|
||||
public CloudEvent DecodeStructuredEvent(byte[] data, IEnumerable<CloudEventAttribute> extensionAttributes) =>
|
||||
public override CloudEvent DecodeStructuredEvent(byte[] data, IEnumerable<CloudEventAttribute> extensionAttributes) =>
|
||||
DecodeStructuredEvent(new MemoryStream(data), extensionAttributes);
|
||||
|
||||
public CloudEvent DecodeGenericRecord(GenericRecord record, IEnumerable<CloudEventAttribute> extensionAttributes)
|
||||
|
@ -106,7 +106,7 @@ namespace CloudNative.CloudEvents
|
|||
return cloudEvent;
|
||||
}
|
||||
|
||||
public byte[] EncodeStructuredEvent(CloudEvent cloudEvent, out ContentType contentType)
|
||||
public override byte[] EncodeStructuredEvent(CloudEvent cloudEvent, out ContentType contentType)
|
||||
{
|
||||
contentType = new ContentType(CloudEvent.MediaType+AvroEventFormatter.MediaTypeSuffix);
|
||||
|
||||
|
@ -148,10 +148,10 @@ namespace CloudNative.CloudEvents
|
|||
}
|
||||
|
||||
// TODO: Validate that this is correct...
|
||||
public byte[] EncodeData(object value) =>
|
||||
public override byte[] EncodeData(object value) =>
|
||||
throw new NotSupportedException("The Avro event formatter does not support binary content mode");
|
||||
|
||||
public object DecodeData(byte[] value, string contentType) =>
|
||||
public override object DecodeData(byte[] value, string contentType) =>
|
||||
throw new NotSupportedException("The Avro event formatter does not support binary content mode");
|
||||
}
|
||||
}
|
|
@ -25,7 +25,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson
|
|||
public CloudEvent DecodeStructuredEvent(Stream data, params CloudEventAttribute[] extensionAttributes) =>
|
||||
DecodeStructuredEvent(data, (IEnumerable<CloudEventAttribute>) extensionAttributes);
|
||||
|
||||
public async Task<CloudEvent> DecodeStructuredEventAsync(Stream data, IEnumerable<CloudEventAttribute> extensionAttributes)
|
||||
public override async Task<CloudEvent> DecodeStructuredEventAsync(Stream data, IEnumerable<CloudEventAttribute> extensionAttributes)
|
||||
{
|
||||
var jsonReader = new JsonTextReader(new StreamReader(data, Encoding.UTF8, true, 8192, true))
|
||||
{
|
||||
|
@ -35,7 +35,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson
|
|||
return DecodeJObject(jObject, extensionAttributes);
|
||||
}
|
||||
|
||||
public CloudEvent DecodeStructuredEvent(Stream data, IEnumerable<CloudEventAttribute> extensionAttributes = null)
|
||||
public override CloudEvent DecodeStructuredEvent(Stream data, IEnumerable<CloudEventAttribute> extensionAttributes = null)
|
||||
{
|
||||
var jsonReader = new JsonTextReader(new StreamReader(data, Encoding.UTF8, true, 8192, true))
|
||||
{
|
||||
|
@ -48,7 +48,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson
|
|||
public CloudEvent DecodeStructuredEvent(byte[] data, params CloudEventAttribute[] extensionAttributes) =>
|
||||
DecodeStructuredEvent(data, (IEnumerable<CloudEventAttribute>)extensionAttributes);
|
||||
|
||||
public CloudEvent DecodeStructuredEvent(byte[] data, IEnumerable<CloudEventAttribute> extensionAttributes = null) =>
|
||||
public override CloudEvent DecodeStructuredEvent(byte[] data, IEnumerable<CloudEventAttribute> extensionAttributes = null) =>
|
||||
DecodeStructuredEvent(new MemoryStream(data), extensionAttributes);
|
||||
|
||||
// TODO: If we make this private, we'll have significantly more control over what token types we see.
|
||||
|
@ -117,7 +117,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson
|
|||
return cloudEvent;
|
||||
}
|
||||
|
||||
public byte[] EncodeStructuredEvent(CloudEvent cloudEvent, out ContentType contentType)
|
||||
public override byte[] EncodeStructuredEvent(CloudEvent cloudEvent, out ContentType contentType)
|
||||
{
|
||||
contentType = new ContentType("application/cloudevents+json")
|
||||
{
|
||||
|
@ -157,7 +157,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson
|
|||
}
|
||||
|
||||
// TODO: How should the caller know whether the result is "raw" or should be stored in data_base64?
|
||||
public byte[] EncodeData(object value)
|
||||
public override byte[] EncodeData(object value)
|
||||
{
|
||||
// TODO: Check this is what we want.
|
||||
// In particular, if this is just other text or binary data, rather than JSON, what does it
|
||||
|
@ -173,7 +173,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson
|
|||
return json is null ? new byte[0] : Encoding.UTF8.GetBytes(json);
|
||||
}
|
||||
|
||||
public object DecodeData(byte[] value, string contentType)
|
||||
public override object DecodeData(byte[] value, string contentType)
|
||||
{
|
||||
if (contentType == "application/json")
|
||||
{
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// Licensed under the Apache 2.0 license.
|
||||
// See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net.Mime;
|
||||
|
@ -12,7 +13,7 @@ namespace CloudNative.CloudEvents
|
|||
/// <summary>
|
||||
/// Implemented by formatters
|
||||
/// </summary>
|
||||
public interface ICloudEventFormatter
|
||||
public abstract class ICloudEventFormatter
|
||||
{
|
||||
/// <summary>
|
||||
/// Decode a structured event from a stream
|
||||
|
@ -20,7 +21,8 @@ namespace CloudNative.CloudEvents
|
|||
/// <param name="data"></param>
|
||||
/// <param name="extensions"></param>
|
||||
/// <returns></returns>
|
||||
CloudEvent DecodeStructuredEvent(Stream data, IEnumerable<CloudEventAttribute> extensionAttributes);
|
||||
public virtual CloudEvent DecodeStructuredEvent(Stream data, IEnumerable<CloudEventAttribute> extensionAttributes) =>
|
||||
throw new NotImplementedException();
|
||||
|
||||
/// <summary>
|
||||
/// Decode a structured event from a stream asynchonously
|
||||
|
@ -28,7 +30,8 @@ namespace CloudNative.CloudEvents
|
|||
/// <param name="data"></param>
|
||||
/// <param name="extensions"></param>
|
||||
/// <returns></returns>
|
||||
Task<CloudEvent> DecodeStructuredEventAsync(Stream data, IEnumerable<CloudEventAttribute> extensionAttributes);
|
||||
public virtual Task<CloudEvent> DecodeStructuredEventAsync(Stream data, IEnumerable<CloudEventAttribute> extensionAttributes) =>
|
||||
throw new NotImplementedException();
|
||||
|
||||
// TODO: Remove either this one or the stream one? It seems unnecessary to have both.
|
||||
|
||||
|
@ -38,7 +41,8 @@ namespace CloudNative.CloudEvents
|
|||
/// <param name="data"></param>
|
||||
/// <param name="extensions"></param>
|
||||
/// <returns></returns>
|
||||
CloudEvent DecodeStructuredEvent(byte[] data, IEnumerable<CloudEventAttribute> extensionAttributes);
|
||||
public virtual CloudEvent DecodeStructuredEvent(byte[] data, IEnumerable<CloudEventAttribute> extensionAttributes) =>
|
||||
throw new NotImplementedException();
|
||||
|
||||
/// <summary>
|
||||
/// Encode an structured event into a byte array
|
||||
|
@ -46,11 +50,12 @@ namespace CloudNative.CloudEvents
|
|||
/// <param name="cloudEvent"></param>
|
||||
/// <param name="contentType"></param>
|
||||
/// <returns></returns>
|
||||
byte[] EncodeStructuredEvent(CloudEvent cloudEvent, out ContentType contentType);
|
||||
|
||||
public virtual byte[] EncodeStructuredEvent(CloudEvent cloudEvent, out ContentType contentType) =>
|
||||
throw new NotImplementedException();
|
||||
|
||||
// TODO: Work out whether this is what we want, and whether to potentially
|
||||
// separate it into a separate interface.
|
||||
byte[] EncodeData(object value);
|
||||
object DecodeData(byte[] value, string contentType);
|
||||
public virtual byte[] EncodeData(object value) => throw new NotImplementedException();
|
||||
public virtual object DecodeData(byte[] value, string contentType) => throw new NotImplementedException();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue