Registry
var codec = CodecBuilder.Create()
.Add<Candle>("application/json", CandleJson.Decode, CandleJson.Encode)
.Add<Trade>("application/json", TradeJson.Decode, TradeJson.Encode)
.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
Tmay 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 withCodecRegistrationException. - 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 notEncode<Candle>(candle, json)and fails withUnknownCodecExceptionnaming both types.- Registration is AOT-safe: dictionaries of delegates, no reflection.