package batteries

  1. Overview
  2. Docs
A community-maintained standard library extension

Install

Dune Dependency

Authors

Maintainers

Sources

v3.9.0.tar.gz
md5=ea26b5c72e6731e59d856626049cca4d
sha512=55975b62c26f6db77433a3ac31f97af609fc6789bb62ac38b267249c78fd44ff37fe81901f1cf560857b9493a6046dd37b0d1c0234c66bd59e52843aac3ce6cb

doc/src/batteries.unthreaded/batMarshal.ml.html

Source file batMarshal.ml

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
(*
 * BatMarshal - Extended marshaling operations
 * Copyright (C) 1997 Xavier Leroy
 *               2008 David Teller
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version,
 * with the special exception on linking described in file LICENSE.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *)


include Marshal

##V<4.2##let from_bytes = from_string
##V<4.2##external to_bytes :
##V<4.2##  'a -> extern_flags list -> Bytes.t = "caml_output_value_to_string"

let output out ?(sharing=true) ?(closures=false) v =
  let flags = match sharing, closures with
    | true, false -> []
    | true, true -> [Closures]
    | false, false -> [No_sharing]
    | false, true -> [No_sharing; Closures]
  in
  let buf = to_string v flags in
  BatInnerIO.nwrite out buf

let input inp =
  let header = Bytes.create header_size in
  let read = BatInnerIO.really_input inp header 0 header_size in
  assert (read = header_size);
  let data_size = data_size header 0 in
  let buf = Bytes.extend header 0 data_size in
  let read = BatInnerIO.really_input inp buf header_size data_size in
  assert (read = data_size);
  from_bytes buf 0

let from_channel = input

let to_channel out v flags =
  BatInnerIO.nwrite out (to_string v flags)


OCaml

Innovation. Community. Security.