123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384# 2 "marshal.ml"(**************************************************************************)(* *)(* OCaml *)(* *)(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)(* *)(* Copyright 1997 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)open!Stdlib[@@@ocaml.flambda_o3]typeextern_flags=No_sharing|Closures|Compat_32(* note: this type definition is used in 'runtime/debugger.c' *)externalto_channel:('a:value_or_null).out_channel->'a->extern_flagslist->unit@@portable="caml_output_value"externalto_bytes:('a:value_or_null).'a->extern_flagslist->bytes@@portable="caml_output_value_to_bytes"externalto_string:('a:value_or_null).'a->extern_flagslist->string@@portable="caml_output_value_to_string"externalto_buffer_unsafe:('a:value_or_null).bytes->int->int->'a->extern_flagslist->int@@portable="caml_output_value_to_buffer"letto_bufferbuffofslenvflags=ifofs<0||len<0||ofs>Bytes.lengthbuff-lentheninvalid_arg"Marshal.to_buffer: substring out of bounds"elseto_buffer_unsafebuffofslenvflags(* The functions below use byte sequences as input, never using any
mutation. It makes sense to use non-mutated [bytes] rather than
[string], because we really work with sequences of bytes, not
a text representation.
*)externalfrom_channel:('a:value_or_null).in_channel->'a@@portable="caml_input_value"externalfrom_bytes_unsafe:('a:value_or_null).bytes->int->'a@@portable="caml_input_value_from_bytes"externaldata_size_unsafe:('a:value_or_null).bytes->int->int@@portable="caml_marshal_data_size"letheader_size=16letdata_sizebuffofs=ifofs<0||ofs>Bytes.lengthbuff-header_sizetheninvalid_arg"Marshal.data_size"elsedata_size_unsafebuffofslettotal_sizebuffofs=header_size+data_sizebuffofsletfrom_bytesbuffofs=ifofs<0||ofs>Bytes.lengthbuff-header_sizetheninvalid_arg"Marshal.from_bytes"elsebeginletlen=data_size_unsafebuffofsinifofs>Bytes.lengthbuff-(header_size+len)theninvalid_arg"Marshal.from_bytes"elsefrom_bytes_unsafebuffofsendletfrom_stringbuffofs=(* Bytes.unsafe_of_string is safe here, as the produced byte
sequence is never mutated *)from_bytes(Bytes.unsafe_of_stringbuff)ofs