1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
open! Base
let = 8
let = Bin_prot.Write.bin_write_int_64bit
let%template[@kind k = (value, float32, float64, bits32, bits64, word)] bin_dump
(type a : k)
?( = false)
(writer : a Bin_prot.Type_class.writer)
(v : a)
=
let buf, pos, pos_len =
let v_len = writer.size v in
if header
then (
let tot_len = v_len + size_header_length in
let buf = Bin_prot.Common.create_buf tot_len in
let pos = bin_write_size_header buf ~pos:0 v_len in
buf, pos, pos + v_len)
else (
let buf = Bin_prot.Common.create_buf v_len in
buf, 0, v_len)
in
let pos = writer.write buf ~pos v in
if pos = pos_len
then buf
else failwith "Bin_prot.Utils.bin_dump: size changed during writing"
;;