Module Bin_prot.Blob
'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
} with bin_ioApplications that need to understand all the details of an event could use:
type concrete_event = Details.t Blob.t event with bin_ioAn 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 with bin_ioThis has two advantages:
- (de)serializing messages is faster because potentially costly (de)serialization of
detailsis avoided - the application can be compiled without any knowledge of any conrete
Details.ttype, so it's robust to changes inDetails.t
An application that's happy to throw away details may use:
type ignored_event = Blob.Ignored.t event with bin_readWhereas opaque_events roundtrip, ignored_events actually drop the bytes representing details when deserializing, and therefore do not roundtrip.
include Binable.S1 with type 'a t = 'a
val bin_shape_t : Shape.t -> Shape.tval bin_size_t : ('a, 'a t) Size.sizer1val bin_write_t : ('a, 'a t) Write.writer1val bin_read_t : ('a, 'a t) Read.reader1val __bin_read_t__ : ('a, int -> 'a t) Read.reader1val bin_writer_t : ('a, 'a t) Type_class.S1.writerval bin_reader_t : ('a, 'a t) Type_class.S1.readerval bin_t : ('a, 'a t) Type_class.S1.t
module Opaque : sig ... endAn
Opaque.Bigstring.torOpaque.String.tis an arbitrary piece of bin-prot. The bin-prot (de-)serializers simply read/write the data, prefixed with its size.
module Ignored : sig ... endAn
Ignored.tis an unusable value with special bin-prot converters. The reader reads the size and drops that much data from the buffer. Writing is not supported, however the size oftis kept, sobin_size_tis available.