Skip to content

Registry

var codec = CodecBuilder.Create()
    .AddClosedCandles()   // market-data-devkit: the protobuf candle, with its schema
    .AddExecutedTrades()  // market-data-devkit: the protobuf trade, with its schema
    .Add<OrderBookView>(OrderBookImage.ContentType, ReadBook, WriteBook)
    .Build();

Add<T>(contentType, decode, encode) registers one wire form. The decoder is Func<CloudEvent, T>; the encoder is Func<T, CloudEvent> and must write the same content type it was registered under.

Keys

Side Key
decode (cloudEvent.DataContentType, typeof(T))
encode (contentType, typeof(T))

application/json is the format of a candle and a trade; the payload type separates them. Binary formats such as application/x-virtufin-orderbook+flatbuffers are usually unambiguous, but the key stays the same.

Rules

  • The same T may be registered under several content types — that is how a value gets a JSON state and a binary event.
  • A duplicate (contentType, T) fails at build time with CodecRegistrationException.
  • The built codec is a snapshot: adding to the builder afterwards does not change it.
  • typeof(T) is the static type. Encode<object>(candle, json) is not Encode<Candle>(candle, json) and fails with UnknownCodecException naming both types.
  • Registration is AOT-safe: dictionaries of delegates, no reflection.