Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ sudo: required
install: wget https://raw.githubusercontent.com/ocaml/ocaml-ci-scripts/master/.travis-opam.sh
script: bash -ex .travis-opam.sh
env:
- OCAML_VERSION=latest TESTS=true PACKAGE=ocplib-endian
- OCAML_VERSION=4.07 TESTS=true PACKAGE=ocplib-endian
- OCAML_VERSION=4.06 TESTS=true PACKAGE=ocplib-endian
- OCAML_VERSION=4.05 TESTS=true PACKAGE=ocplib-endian
- OCAML_VERSION=4.04 TESTS=true PACKAGE=ocplib-endian
- OCAML_VERSION=4.03 TESTS=true PACKAGE=ocplib-endian
- OCAML_VERSION=4.02 TESTS=true PACKAGE=ocplib-endian
Expand Down
2 changes: 2 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(lang dune 1.0)
(name ocplib-endian)
6 changes: 3 additions & 3 deletions ocplib-endian.opam
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ bug-reports: "https://github.com/OCamlPro/ocplib-endian/issues"
depends: [
"base-bytes"
"cppo" {>= "1.1.0"}
"jbuilder" {build}
"dune" {build & >= "1.0"}
]
build: [
["jbuilder" "build" "--only-packages" "ocplib-endian" "--root" "." "-j" jobs "@install"]
["dune" "build" "-p" name "-j" jobs]
]
build-test: [
["jbuilder" "runtest" "--only-packages" "ocplib-endian" "--root" "." "-j" jobs]
["dune" "runtest" "-p" name "-j" jobs]
]
dev-repo: "git+https://github.com/OCamlPro/ocplib-endian.git"
url {
Expand Down
12 changes: 12 additions & 0 deletions src/common_400.cppo.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module BigEndian = struct

type nonrec t = t

let get_char = get_char
let get_uint8 = get_uint8
let get_int8 = get_int8
Expand All @@ -13,6 +15,8 @@ end

module BigEndian_unsafe = struct

type nonrec t = t

let get_char = unsafe_get_char
let get_uint8 = unsafe_get_uint8
let get_int8 = unsafe_get_int8
Expand All @@ -26,6 +30,8 @@ end

module LittleEndian = struct

type nonrec t = t

let get_char = get_char
let get_uint8 = get_uint8
let get_int8 = get_int8
Expand All @@ -39,6 +45,8 @@ end

module LittleEndian_unsafe = struct

type nonrec t = t

let get_char = unsafe_get_char
let get_uint8 = unsafe_get_uint8
let get_int8 = unsafe_get_int8
Expand All @@ -53,6 +61,8 @@ end
#if OCAML_VERSION >= (4, 00, 0)
module NativeEndian = struct

type nonrec t = t

let get_char = get_char
let get_uint8 = get_uint8
let get_int8 = get_int8
Expand All @@ -66,6 +76,8 @@ end

module NativeEndian_unsafe = struct

type nonrec t = t

let get_char = unsafe_get_char
let get_uint8 = unsafe_get_uint8
let get_int8 = unsafe_get_int8
Expand Down
12 changes: 12 additions & 0 deletions src/common_401.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ external swapnative : nativeint -> nativeint = "%bswap_native"

module BigEndian = struct

type nonrec t = t

let get_char = get_char
let get_uint8 = get_uint8
let get_int8 = get_int8
Expand All @@ -18,6 +20,8 @@ end

module BigEndian_unsafe = struct

type nonrec t = t

let get_char = unsafe_get_char
let get_uint8 = unsafe_get_uint8
let get_int8 = unsafe_get_int8
Expand All @@ -37,6 +41,8 @@ end

module LittleEndian = struct

type nonrec t = t

let get_char = get_char
let get_uint8 = get_uint8
let get_int8 = get_int8
Expand All @@ -50,6 +56,8 @@ end

module LittleEndian_unsafe = struct

type nonrec t = t

let get_char = unsafe_get_char
let get_uint8 = unsafe_get_uint8
let get_int8 = unsafe_get_int8
Expand All @@ -69,6 +77,8 @@ end

module NativeEndian = struct

type nonrec t = t

let get_char = get_char
let get_uint8 = get_uint8
let get_int8 = get_int8
Expand All @@ -82,6 +92,8 @@ end

module NativeEndian_unsafe = struct

type nonrec t = t

let get_char = unsafe_get_char
let get_uint8 = unsafe_get_uint8
let get_int8 = unsafe_get_int8
Expand Down
100 changes: 100 additions & 0 deletions src/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
(rule
(targets endianString.mli)
(deps
(:< endianString.cppo.mli))
(action
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{<} -o %{targets})))

(rule
(targets endianString.ml)
(deps
(:< endianString.cppo.ml)
common.ml
common_401.ml
common_400.ml)
(action
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{<} -o %{targets})))

(rule
(targets endianBytes.mli)
(deps
(:< endianBytes.cppo.mli))
(action
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{<} -o %{targets})))

(rule
(targets endianBytes.ml)
(deps
(:< endianBytes.cppo.ml)
common.ml
common_401.ml
common_400.ml)
(action
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{<} -o %{targets})))

(rule
(targets endianBigstring.mli)
(deps
(:< endianBigstring.cppo.mli))
(action
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{<} -o %{targets})))

(rule
(targets endianBigstring.ml)
(deps
(:< endianBigstring.cppo.ml)
common.ml
common_401.ml
common_400.ml)
(action
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{<} -o %{targets})))

(rule
(targets common_400.ml)
(deps
(:< common_400.cppo.ml)
be_ocaml_400.ml
le_ocaml_400.ml
ne_ocaml_400.ml
common_float.ml)
(action
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{<} -o %{targets})))

(rule
(targets common_401.ml)
(deps
(:< common_401.cppo.ml)
be_ocaml_401.ml
le_ocaml_401.ml
ne_ocaml_401.ml
common_float.ml)
(action
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{<} -o %{targets})))

(library
(name ocplib_endian_sig)
(public_name ocplib-endian.sig)
(synopsis
"Optimised functions to read and write int16/32/64 from strings and bytes")
(wrapped false)
(flags -w -52)
(modules endianSig)
(libraries bytes))

(library
(name ocplib_endian)
(public_name ocplib-endian)
(synopsis
"Optimised functions to read and write int16/32/64 from strings and bytes")
(wrapped false)
(flags -w -52)
(modules endianString endianBytes)
(libraries bytes ocplib-endian.sig))

(library
(name ocplib_endian_bigstring)
(public_name ocplib-endian.bigstring)
(synopsis "Optimised functions to read and write int16/32/64 from bigarrays")
(wrapped false)
(modules endianBigstring)
(libraries ocplib_endian bigarray bytes ocplib-endian.sig))
62 changes: 2 additions & 60 deletions src/endianBigstring.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,68 +18,10 @@
open Bigarray

type bigstring = (char, int8_unsigned_elt, c_layout) Array1.t
type t = bigstring

module type EndianBigstringSig = sig
(** Functions reading according to Big Endian byte order *)

val get_char : bigstring -> int -> char
(** [get_char buff i] reads 1 byte at offset i as a char *)

val get_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 *)

val get_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 *)

val get_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 *)

val get_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 *)

val get_int32 : bigstring -> int -> int32
(** [get_int32 buff i] reads 4 bytes at offset i as an int32. *)

val get_int64 : bigstring -> int -> int64
(** [get_int64 buff i] reads 8 bytes at offset i as an int64. *)

val get_float : bigstring -> int -> float
(** [get_float buff i] is equivalent to
[Int32.float_of_bits (get_int32 buff i)] *)

val get_double : bigstring -> int -> float
(** [get_double buff i] is equivalent to
[Int64.float_of_bits (get_int64 buff i)] *)

val set_char : bigstring -> int -> char -> unit
(** [set_char buff i v] writes [v] to [buff] at offset [i] *)

val set_int8 : bigstring -> int -> int -> unit
(** [set_int8 buff i v] writes the least significant 8 bits of [v]
to [buff] at offset [i] *)

val set_int16 : bigstring -> int -> int -> unit
(** [set_int16 buff i v] writes the least significant 16 bits of [v]
to [buff] at offset [i] *)

val set_int32 : bigstring -> int -> int32 -> unit
(** [set_int32 buff i v] writes [v] to [buff] at offset [i] *)

val set_int64 : bigstring -> int -> int64 -> unit
(** [set_int64 buff i v] writes [v] to [buff] at offset [i] *)

val set_float : bigstring -> int -> float -> unit
(** [set_float buff i v] is equivalent to
[set_int32 buff i (Int32.bits_of_float v)] *)

val set_double : bigstring -> int -> float -> unit
(** [set_double buff i v] is equivalent to
[set_int64 buff i (Int64.bits_of_float v)] *)

include EndianSig.FULL with type t = bigstring
end

let get_char (s:bigstring) off =
Expand Down
61 changes: 1 addition & 60 deletions src/endianBigstring.cppo.mli
Original file line number Diff line number Diff line change
Expand Up @@ -19,66 +19,7 @@ open Bigarray
type bigstring = (char, int8_unsigned_elt, c_layout) Array1.t

module type EndianBigstringSig = sig
(** Functions reading according to Big Endian byte order *)

val get_char : bigstring -> int -> char
(** [get_char buff i] reads 1 byte at offset i as a char *)

val get_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 *)

val get_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 *)

val get_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 *)

val get_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 *)

val get_int32 : bigstring -> int -> int32
(** [get_int32 buff i] reads 4 bytes at offset i as an int32. *)

val get_int64 : bigstring -> int -> int64
(** [get_int64 buff i] reads 8 bytes at offset i as an int64. *)

val get_float : bigstring -> int -> float
(** [get_float buff i] is equivalent to
[Int32.float_of_bits (get_int32 buff i)] *)

val get_double : bigstring -> int -> float
(** [get_double buff i] is equivalent to
[Int64.float_of_bits (get_int64 buff i)] *)

val set_char : bigstring -> int -> char -> unit
(** [set_char buff i v] writes [v] to [buff] at offset [i] *)

val set_int8 : bigstring -> int -> int -> unit
(** [set_int8 buff i v] writes the least significant 8 bits of [v]
to [buff] at offset [i] *)

val set_int16 : bigstring -> int -> int -> unit
(** [set_int16 buff i v] writes the least significant 16 bits of [v]
to [buff] at offset [i] *)

val set_int32 : bigstring -> int -> int32 -> unit
(** [set_int32 buff i v] writes [v] to [buff] at offset [i] *)

val set_int64 : bigstring -> int -> int64 -> unit
(** [set_int64 buff i v] writes [v] to [buff] at offset [i] *)

val set_float : bigstring -> int -> float -> unit
(** [set_float buff i v] is equivalent to
[set_int32 buff i (Int32.bits_of_float v)] *)

val set_double : bigstring -> int -> float -> unit
(** [set_double buff i v] is equivalent to
[set_int64 buff i (Int64.bits_of_float v)] *)

include EndianSig.FULL with type t = bigstring
end

module BigEndian : sig
Expand Down
Loading