Bin_prot.BlobSource'a Blob.t is type-equivalent to 'a, but has different bin-prot serializers that prefix the representation with the size of 'a.
To understand where this is useful, imagine we have an event type where many applications look at some parts of an event, but not all applications need to deal with all parts of an event. We might define:
type 'a event =
{ time : Time.t
; source : string
; details : 'a
} [@@deriving bin_io]Applications that need to understand all the details of an event could use:
type concrete_event = Details.t Blob.t event [@@deriving bin_io] An application that filters events to downsteam consumers based on just source or time (but doesn't need to parse details) may use:
type opaque_event = Blob.Opaque.Bigstring.t event [@@deriving bin_io] This has two advantages:
details is avoidedDetails.t type, so it's robust to changes in Details.tAn application that's happy to throw away details may use:
type ignored_event = Blob.Ignored.t event [@@deriving bin_read] Whereas opaque_events roundtrip, ignored_events actually drop the bytes representing details when deserializing, and therefore do not roundtrip.
An Opaque.Bigstring.t or Opaque.String.t is an arbitrary piece of bin-prot. The bin-prot (de-)serializers simply read/write the data, prefixed with its size.