123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546# 1 "endianBigstring.cppo.ml"(************************************************************************)(* ocplib-endian *)(* *)(* Copyright 2012 OCamlPro *)(* *)(* This file is distributed 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 OCaml static compilation exception. *)(* *)(* ocplib-endian 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 General Public License for more details. *)(* *)(************************************************************************)openBigarraytypebigstring=(char,int8_unsigned_elt,c_layout)Array1.tmoduletypeEndianBigstringSig=sig(** Functions reading according to Big Endian byte order *)valget_char:bigstring->int->char(** [get_char buff i] reads 1 byte at offset i as a char *)valget_uint8:bigstring->int->int(** [get_uint8 buff i] reads 1 byte at offset i as an unsigned int of 8
bits. i.e. It returns a value between 0 and 2^8-1 *)valget_int8:bigstring->int->int(** [get_int8 buff i] reads 1 byte at offset i as a signed int of 8
bits. i.e. It returns a value between -2^7 and 2^7-1 *)valget_uint16:bigstring->int->int(** [get_uint16 buff i] reads 2 bytes at offset i as an unsigned int
of 16 bits. i.e. It returns a value between 0 and 2^16-1 *)valget_int16:bigstring->int->int(** [get_int16 buff i] reads 2 byte at offset i as a signed int of
16 bits. i.e. It returns a value between -2^15 and 2^15-1 *)valget_int32:bigstring->int->int32(** [get_int32 buff i] reads 4 bytes at offset i as an int32. *)valget_int64:bigstring->int->int64(** [get_int64 buff i] reads 8 bytes at offset i as an int64. *)valget_float:bigstring->int->float(** [get_float buff i] is equivalent to
[Int32.float_of_bits (get_int32 buff i)] *)valget_double:bigstring->int->float(** [get_double buff i] is equivalent to
[Int64.float_of_bits (get_int64 buff i)] *)valset_char:bigstring->int->char->unit(** [set_char buff i v] writes [v] to [buff] at offset [i] *)valset_int8:bigstring->int->int->unit(** [set_int8 buff i v] writes the least significant 8 bits of [v]
to [buff] at offset [i] *)valset_int16:bigstring->int->int->unit(** [set_int16 buff i v] writes the least significant 16 bits of [v]
to [buff] at offset [i] *)valset_int32:bigstring->int->int32->unit(** [set_int32 buff i v] writes [v] to [buff] at offset [i] *)valset_int64:bigstring->int->int64->unit(** [set_int64 buff i v] writes [v] to [buff] at offset [i] *)valset_float:bigstring->int->float->unit(** [set_float buff i v] is equivalent to
[set_int32 buff i (Int32.bits_of_float v)] *)valset_double:bigstring->int->float->unit(** [set_double buff i v] is equivalent to
[set_int64 buff i (Int64.bits_of_float v)] *)endletget_char(s:bigstring)off=Array1.getsoff[@@ocaml.inline]letset_char(s:bigstring)offv=Array1.setsoffv[@@ocaml.inline]letunsafe_get_char(s:bigstring)off=Array1.unsafe_getsoff[@@ocaml.inline]letunsafe_set_char(s:bigstring)offv=Array1.unsafe_setsoffv[@@ocaml.inline]# 1 "common.ml"[@@@warning"-32"]letsign8v=(vlsl(Sys.int_size-8))asr(Sys.int_size-8)[@@ocaml.inline]letsign16v=(vlsl(Sys.int_size-16))asr(Sys.int_size-16)[@@ocaml.inline]letget_uint8soff=Char.code(get_charsoff)[@@ocaml.inline]letget_int8soff=((get_uint8soff)lsl(Sys.int_size-8))asr(Sys.int_size-8)[@@ocaml.inline]letset_int8soffv=(* It is ok to cast using unsafe_chr because both String.set
and Bigarray.Array1.set (on bigstrings) use the 'store unsigned int8'
primitives that effectively extract the bits before writing *)set_charsoff(Char.unsafe_chrv)[@@ocaml.inline]letunsafe_get_uint8soff=Char.code(unsafe_get_charsoff)[@@ocaml.inline]letunsafe_get_int8soff=((unsafe_get_uint8soff)lsl(Sys.int_size-8))asr(Sys.int_size-8)[@@ocaml.inline]letunsafe_set_int8soffv=unsafe_set_charsoff(Char.unsafe_chrv)[@@ocaml.inline]# 100 "endianBigstring.cppo.ml"externalunsafe_get_16:bigstring->int->int="%caml_bigstring_get16u"externalunsafe_get_32:bigstring->int->int32="%caml_bigstring_get32u"externalunsafe_get_64:bigstring->int->int64="%caml_bigstring_get64u"externalunsafe_set_16:bigstring->int->int->unit="%caml_bigstring_set16u"externalunsafe_set_32:bigstring->int->int32->unit="%caml_bigstring_set32u"externalunsafe_set_64:bigstring->int->int64->unit="%caml_bigstring_set64u"externalget_16:bigstring->int->int="%caml_bigstring_get16"externalget_32:bigstring->int->int32="%caml_bigstring_get32"externalget_64:bigstring->int->int64="%caml_bigstring_get64"externalset_16:bigstring->int->int->unit="%caml_bigstring_set16"externalset_32:bigstring->int->int32->unit="%caml_bigstring_set32"externalset_64:bigstring->int->int64->unit="%caml_bigstring_set64"# 1 "common_401.cppo.ml"# 1 "common_401.cppo.ml"externalswap16:int->int="%bswap16"externalswap32:int32->int32="%bswap_int32"externalswap64:int64->int64="%bswap_int64"externalswapnative:nativeint->nativeint="%bswap_native"moduleBigEndian=structletget_char=get_charletget_uint8=get_uint8letget_int8=get_int8letset_char=set_charletset_int8=set_int8# 1 "be_ocaml_401.ml"# 1 "be_ocaml_401.ml"letget_uint16soff=ifnotSys.big_endianthenswap16(get_16soff)elseget_16soff[@@ocaml.inline]letget_int16soff=((get_uint16soff)lsl(Sys.int_size-16))asr(Sys.int_size-16)[@@ocaml.inline]letget_int32soff=ifnotSys.big_endianthenswap32(get_32soff)elseget_32soff[@@ocaml.inline]letget_int64soff=ifnotSys.big_endianthenswap64(get_64soff)elseget_64soff[@@ocaml.inline]letset_int16soffv=ifnotSys.big_endianthen(set_16soff(swap16v))elseset_16soffv[@@ocaml.inline]letset_int32soffv=ifnotSys.big_endianthenset_32soff(swap32v)elseset_32soffv[@@ocaml.inline]letset_int64soffv=ifnotSys.big_endianthenset_64soff(swap64v)elseset_64soffv[@@ocaml.inline]# 2 "common_float.ml"# 2 "common_float.ml"letget_floatbuffi=Int32.float_of_bits(get_int32buffi)[@@ocaml.inline]letget_doublebuffi=Int64.float_of_bits(get_int64buffi)[@@ocaml.inline]letset_floatbuffiv=set_int32buffi(Int32.bits_of_floatv)[@@ocaml.inline]letset_doublebuffiv=set_int64buffi(Int64.bits_of_floatv)[@@ocaml.inline]# 17 "common_401.cppo.ml"# 17 "common_401.cppo.ml"endmoduleBigEndian_unsafe=structletget_char=unsafe_get_charletget_uint8=unsafe_get_uint8letget_int8=unsafe_get_int8letset_char=unsafe_set_charletset_int8=unsafe_set_int8letget_16=unsafe_get_16letget_32=unsafe_get_32letget_64=unsafe_get_64letset_16=unsafe_set_16letset_32=unsafe_set_32letset_64=unsafe_set_64# 1 "be_ocaml_401.ml"# 1 "be_ocaml_401.ml"letget_uint16soff=ifnotSys.big_endianthenswap16(get_16soff)elseget_16soff[@@ocaml.inline]letget_int16soff=((get_uint16soff)lsl(Sys.int_size-16))asr(Sys.int_size-16)[@@ocaml.inline]letget_int32soff=ifnotSys.big_endianthenswap32(get_32soff)elseget_32soff[@@ocaml.inline]letget_int64soff=ifnotSys.big_endianthenswap64(get_64soff)elseget_64soff[@@ocaml.inline]letset_int16soffv=ifnotSys.big_endianthen(set_16soff(swap16v))elseset_16soffv[@@ocaml.inline]letset_int32soffv=ifnotSys.big_endianthenset_32soff(swap32v)elseset_32soffv[@@ocaml.inline]letset_int64soffv=ifnotSys.big_endianthenset_64soff(swap64v)elseset_64soffv[@@ocaml.inline]# 2 "common_float.ml"# 2 "common_float.ml"letget_floatbuffi=Int32.float_of_bits(get_int32buffi)[@@ocaml.inline]letget_doublebuffi=Int64.float_of_bits(get_int64buffi)[@@ocaml.inline]letset_floatbuffiv=set_int32buffi(Int32.bits_of_floatv)[@@ocaml.inline]letset_doublebuffiv=set_int64buffi(Int64.bits_of_floatv)[@@ocaml.inline]# 36 "common_401.cppo.ml"# 36 "common_401.cppo.ml"endmoduleLittleEndian=structletget_char=get_charletget_uint8=get_uint8letget_int8=get_int8letset_char=set_charletset_int8=set_int8# 1 "le_ocaml_401.ml"# 1 "le_ocaml_401.ml"letget_uint16soff=ifSys.big_endianthenswap16(get_16soff)elseget_16soff[@@ocaml.inline]letget_int16soff=((get_uint16soff)lsl(Sys.int_size-16))asr(Sys.int_size-16)[@@ocaml.inline]letget_int32soff=ifSys.big_endianthenswap32(get_32soff)elseget_32soff[@@ocaml.inline]letget_int64soff=ifSys.big_endianthenswap64(get_64soff)elseget_64soff[@@ocaml.inline]letset_int16soffv=ifSys.big_endianthen(set_16soff(swap16v))elseset_16soffv[@@ocaml.inline]letset_int32soffv=ifSys.big_endianthenset_32soff(swap32v)elseset_32soffv[@@ocaml.inline]letset_int64soffv=ifSys.big_endianthenset_64soff(swap64v)elseset_64soffv[@@ocaml.inline]# 2 "common_float.ml"# 2 "common_float.ml"letget_floatbuffi=Int32.float_of_bits(get_int32buffi)[@@ocaml.inline]letget_doublebuffi=Int64.float_of_bits(get_int64buffi)[@@ocaml.inline]letset_floatbuffiv=set_int32buffi(Int32.bits_of_floatv)[@@ocaml.inline]letset_doublebuffiv=set_int64buffi(Int64.bits_of_floatv)[@@ocaml.inline]# 49 "common_401.cppo.ml"# 49 "common_401.cppo.ml"endmoduleLittleEndian_unsafe=structletget_char=unsafe_get_charletget_uint8=unsafe_get_uint8letget_int8=unsafe_get_int8letset_char=unsafe_set_charletset_int8=unsafe_set_int8letget_16=unsafe_get_16letget_32=unsafe_get_32letget_64=unsafe_get_64letset_16=unsafe_set_16letset_32=unsafe_set_32letset_64=unsafe_set_64# 1 "le_ocaml_401.ml"# 1 "le_ocaml_401.ml"letget_uint16soff=ifSys.big_endianthenswap16(get_16soff)elseget_16soff[@@ocaml.inline]letget_int16soff=((get_uint16soff)lsl(Sys.int_size-16))asr(Sys.int_size-16)[@@ocaml.inline]letget_int32soff=ifSys.big_endianthenswap32(get_32soff)elseget_32soff[@@ocaml.inline]letget_int64soff=ifSys.big_endianthenswap64(get_64soff)elseget_64soff[@@ocaml.inline]letset_int16soffv=ifSys.big_endianthen(set_16soff(swap16v))elseset_16soffv[@@ocaml.inline]letset_int32soffv=ifSys.big_endianthenset_32soff(swap32v)elseset_32soffv[@@ocaml.inline]letset_int64soffv=ifSys.big_endianthenset_64soff(swap64v)elseset_64soffv[@@ocaml.inline]# 2 "common_float.ml"# 2 "common_float.ml"letget_floatbuffi=Int32.float_of_bits(get_int32buffi)[@@ocaml.inline]letget_doublebuffi=Int64.float_of_bits(get_int64buffi)[@@ocaml.inline]letset_floatbuffiv=set_int32buffi(Int32.bits_of_floatv)[@@ocaml.inline]letset_doublebuffiv=set_int64buffi(Int64.bits_of_floatv)[@@ocaml.inline]# 68 "common_401.cppo.ml"# 68 "common_401.cppo.ml"endmoduleNativeEndian=structletget_char=get_charletget_uint8=get_uint8letget_int8=get_int8letset_char=set_charletset_int8=set_int8# 1 "ne_ocaml_401.ml"# 1 "ne_ocaml_401.ml"letget_uint16soff=get_16soff[@@ocaml.inline]letget_int16soff=((get_uint16soff)lsl(Sys.int_size-16))asr(Sys.int_size-16)[@@ocaml.inline]letget_int32soff=get_32soff[@@ocaml.inline]letget_int64soff=get_64soff[@@ocaml.inline]letset_int16soffv=set_16soffv[@@ocaml.inline]letset_int32soffv=set_32soffv[@@ocaml.inline]letset_int64soffv=set_64soffv[@@ocaml.inline]# 2 "common_float.ml"# 2 "common_float.ml"letget_floatbuffi=Int32.float_of_bits(get_int32buffi)[@@ocaml.inline]letget_doublebuffi=Int64.float_of_bits(get_int64buffi)[@@ocaml.inline]letset_floatbuffiv=set_int32buffi(Int32.bits_of_floatv)[@@ocaml.inline]letset_doublebuffiv=set_int64buffi(Int64.bits_of_floatv)[@@ocaml.inline]# 81 "common_401.cppo.ml"# 81 "common_401.cppo.ml"endmoduleNativeEndian_unsafe=structletget_char=unsafe_get_charletget_uint8=unsafe_get_uint8letget_int8=unsafe_get_int8letset_char=unsafe_set_charletset_int8=unsafe_set_int8letget_16=unsafe_get_16letget_32=unsafe_get_32letget_64=unsafe_get_64letset_16=unsafe_set_16letset_32=unsafe_set_32letset_64=unsafe_set_64# 1 "ne_ocaml_401.ml"# 1 "ne_ocaml_401.ml"letget_uint16soff=get_16soff[@@ocaml.inline]letget_int16soff=((get_uint16soff)lsl(Sys.int_size-16))asr(Sys.int_size-16)[@@ocaml.inline]letget_int32soff=get_32soff[@@ocaml.inline]letget_int64soff=get_64soff[@@ocaml.inline]letset_int16soffv=set_16soffv[@@ocaml.inline]letset_int32soffv=set_32soffv[@@ocaml.inline]letset_int64soffv=set_64soffv[@@ocaml.inline]# 2 "common_float.ml"# 2 "common_float.ml"letget_floatbuffi=Int32.float_of_bits(get_int32buffi)[@@ocaml.inline]letget_doublebuffi=Int64.float_of_bits(get_int64buffi)[@@ocaml.inline]letset_floatbuffiv=set_int32buffi(Int32.bits_of_floatv)[@@ocaml.inline]letset_doublebuffiv=set_int64buffi(Int64.bits_of_floatv)[@@ocaml.inline]# 100 "common_401.cppo.ml"# 100 "common_401.cppo.ml"end