Module Opaque.String
include Bin_prot.Binable.S
include Bin_prot.Binable.S_only_functions with type t := t
val bin_size_t : t Bin_prot.Size.sizerval bin_write_t : t Bin_prot.Write.writerval bin_read_t : t Bin_prot.Read.readerval __bin_read_t__ : (int -> t) Bin_prot.Read.readerThis function only needs implementation if
texposed to be a polymorphic variant. Despite what the type reads, this does *not* produce a function after reading; instead it takes the constructor tag (int) before reading and reads the rest of the varianttafterwards.
val bin_shape_t : Bin_prot.Shape.tval bin_writer_t : t Bin_prot.Type_class.writerval bin_reader_t : t Bin_prot.Type_class.readerval bin_t : t Bin_prot.Type_class.t
val length : t -> intFor performance's concern, we require caller of
to_opaqueandof_opaque_exnto pass in thebufas the intermediate buffer for bin_prot conversion. These two functions will write bytes into the buffer, but will not resize the buffer. So the caller should prepare big enough buffer for their need.For
of_opaque_exn t, the minimum buffer size should belength t.For
to_opaquethe necessary buffer size can be computed usingsizefrom Type_class.writer or you can catch the exceptionBin_prot.Common.Buffer_short(although the latter is not very reliable because some custom bin_io implementations raise a different exception).Additional caveat: if the opaque blob is malformed/partial then
of_opaque_exncan read past the end of the blob, which can result in:- confusing/non-deterministic error messages (referring to the contents of
bufrather than the contents of the blob) - degraded performance (having to read through the buffer just to fail at the end)
- confusing/non-deterministic error messages (referring to the contents of
val to_opaque : buf:Bin_prot.Common.buf -> 'a -> 'a Bin_prot.Type_class.writer -> tval of_opaque_exn : buf:Bin_prot.Common.buf -> t -> 'a Bin_prot.Type_class.reader -> 'a