janestreet / bin_prot

Binary protocol generator
MIT License
73 stars 21 forks source link

Documentation link is broken #24

Closed Gau-thier closed 1 year ago

Gau-thier commented 2 years ago

Hi! First of all, thanks for this tool. It looks pretty great!

This issue has two purposes:

  1. Signal there is a broken link in documentation
  2. Ask for examples of custom bin_read_t instances.

Broken link in readme.md

I was hoping to find some examples in the HTML doc mentioned in the readme.md, but the link leads to an HTTP 404.

Help on custom instances

I am trying to define custom bin_read_t instances:

type t [@@deriving yojson, bin_read, bin_write]
val bin_read_t : t Bin_prot.Read.reader

Cheers,

Gauthier

aalekseyev commented 2 years ago

Sorry for long delay on this. Indeed I can't see a unified documentation on writing custom instances. Generally my advice would be to look at implementations in std.ml and draw inspiration from them.

The relevant doc pieces that I found include: in write.mli:

(** Type of writer functions for the binary protocol. They take a buffer,
    a write position and a value, and return the next position after
    writing out the value. *)
type 'a writer = buf -> pos:pos -> 'a -> pos

sizer goes without the doc, but its purpose is to determine the size of the value that [write] will write.

read.mli has this:

(** Type of reader functions for the binary protocol.  They take a
    buffer and a reference to a read position, and return the unmarshalled
    value.  The next buffer position after reading in the value will be
    stored in the position reference. *)
type 'a reader = buf -> pos_ref:pos_ref -> 'a

A comment in binable.ml mentions what __bin_read_t__ is about.

For shape, there's something in the "User defined bin_prot" section in shape/README.md, although you probably don't care too much about that.

staronj commented 1 year ago

This was fixed internally and will soon be pushed upstream.