Support `custom` in `Binary` too
Currently custom is available in Json. A similar function would be useful for Binary. Basically something along the lines of:
val custom:
<'a serialiser_type> ->
<'a deserialiser_type> ->
'a encoding
The type of serialisers could be as simple as 'a -> bytes (and the bytes would be blitted directly) or equivalently 'a -> unit8 list (where uint8 is a 0-255 integer).
Alternatively, we can "encourage" the use of the fixed endianess: (module type of TzEndian) -> 'a -> bytes
Alternatively, we can pass a more constraining set of functions: (module WRITER) -> 'a -> bytes where WRITER has a collection of functions like add_int8, add_int16, …, add_int64
For deserialisers, we can have type decoder_state = { offset : int; source : string; … } and then have decoder_state -> (decoder_state * 'a).
Alternatively simply string -> int -> (int * 'a)
Use case:
- implementing Z and N as non-built-ins
- UTF8
Additional considerations:
- Needs to support errors. So there should be a way for the serialiser/deserialiser to return
Error _. - We need to pass a name and description for the binary schema
- We need to pass optional
sizeand other such metadata info