Skip to content

FlatBuffers

FlatBuffers is a normal registration. The existing book image already carries everything the registry needs:

OrderBookImage.ContentType = "application/x-virtufin-orderbook+flatbuffers";
OrderBookImage.DataSchema  = urn:virtufin:marketdata:orderbook:v1;
OrderBookImage.Read(byte[])  -> OrderBookView   // verifies id + offsets
OrderBookImage.Encode(...)   -> byte[]
.Add<OrderBookView>(
    OrderBookImage.ContentType,
    ce => OrderBookImage.Read(CodecBytes.From(ce)),
    view => new CloudEvent
    {
        Data = BookImage.Encode(view),
        DataContentType = OrderBookImage.ContentType,
        DataSchema = OrderBookImage.DataSchema,
    })

Read the bytes through CodecBytes

CloudEvent.Data is byte[], Memory<byte>, ReadOnlyMemory<byte>, ArraySegment<byte> or a base64 string, depending on the transport. CodecBytes.From(ce) normalizes all of them and throws PayloadDecodeException for anything else — a binary decoder should never cast Data itself.

Borrowed memory

OrderBookView is a struct over the event's buffer. It is valid while the event is alive; a window or an indicator must not retain it. Fold derived values (mid, spread, imbalance) or copy into L2OrderBook. The codec's boxed value is one small struct, not a copy of the image.

Errors

OrderBookImage.Read throws InvalidDataException for a wrong identifier or an out-of-bounds offset. The codec wraps it as PayloadDecodeException with the original exception preserved — the boundary never leaks a platform exception.