Table of Contents

Namespace Virtufin.Worker.DevKit.Codecs

Classes

CodecBuilder

Creates a ICodec registry.

CodecBytes

Turns an event's data into bytes for a binary codec (FlatBuffers, a compact venue frame, ...), whatever representation the transport left in Data: byte[], Memory<T>, ReadOnlyMemory<T>, ArraySegment<T> or a base64 string.

A binary decoder should call this rather than cast Data itself: a representation it did not expect becomes a PayloadDecodeException, never an InvalidCastException or a NullReferenceException.

CodecException

The domain exceptions of the codec registry. No public codec member throws a platform exception: argument problems, missing registrations, decoder failures and type mismatches are all reported through this hierarchy, with the offending content type, payload type and event id on every instance.

CodecRegistrationException

A registration is invalid: duplicate key, null delegate, empty content type.

CodecUsageException

The codec was called incorrectly (a null event, a null delegate).

PayloadDecodeException

A decoder failed; its exception is preserved as InnerException.

PayloadEncodeException

An encoder failed or produced a different datacontenttype than requested.

PayloadTypeMismatchException

A decoder returned a value that is not the requested payload type (including null).

UnknownCodecException

No decoder or encoder is registered for the content type and payload type.

Interfaces

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.

ICodecBuilder

Builds a ICodec from typed registrations.