OCamlPro / flambda-task-force

13 stars 1 forks source link

Verify the functional deserialisation pattern #11

Open chambart opened 9 years ago

chambart commented 9 years ago

Something like that:

type buffer = { buffer : string; offset : int; length : int }
let read_int32 buf =
  if buf.offset + 4 >= length then raise Some_error
  else
    let result = read_int32_from_string buf.buffer buf.offset in
    { buf = buf with offset = buf.offset + 4 }

Successions of read shouldn't allocate too much. This is a pattern heavily used in cstruct generated code.

mshinwell commented 8 years ago

Maybe add something to the asmcomp/ testsuite.