Interface ICodec
Payload ⇄ CloudEvent data, selected by datacontenttype and payload
type.
Decode<T>(CloudEvent) reads the event's datacontenttype (absent:
application/json, the CloudEvents default) and the requested payload
type. Encode<T>(T, string) is given both: a payload type may have more
than one wire form (JSON for state, FlatBuffers for the event), so the caller
names the format and the codec never guesses.
Every failure is a CodecException: no
NullReferenceException, InvalidCastException,
KeyNotFoundException or JsonException escapes. The
encoder's own datacontenttype is asserted against the requested one.
public interface ICodec
Methods
Decode<T>(CloudEvent)
Decode the event as T.
T Decode<T>(CloudEvent cloudEvent)
Parameters
cloudEventCloudEvent
Returns
- T
Type Parameters
T
Exceptions
- CodecException
No codec, a failed decoder, or a payload of another type.
Encode<T>(T, string)
Encode payload as contentType.
CloudEvent Encode<T>(T payload, string contentType)
Parameters
payloadTThe value; its static type selects the encoder.
contentTypestringThe wire format, e.g.
application/json.
Returns
Type Parameters
T
Exceptions
- CodecException
No codec, a failed or mislabelled encoder, or a null payload.