-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbigbytes.ml
More file actions
58 lines (45 loc) · 1.4 KB
/
bigbytes.ml
File metadata and controls
58 lines (45 loc) · 1.4 KB
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
55
56
57
58
type bigbytes =
(char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t
(*
module type S = sig
type t
type ctype
val ctype : ctype typ
val create : int -> t
val zero : t -> int -> int -> unit
val blit : t -> int -> t -> int -> int -> unit
val sub : t -> int -> int -> t
val length : t -> int
val len_size_t : t -> PosixTypes.size_t
val len_ullong : t -> Unsigned.ullong
val to_ptr : t -> ctype
val to_bytes : t -> Bytes.t
val of_bytes : Bytes.t -> t
end
*)
type t = bigbytes
(*
type ctype = char ptr
let ctype = ptr char
*)
open Bigarray
let create len = (Array1.create char c_layout len)
let length str = Array1.dim str
(*
let len_size_t str = Unsigned.Size_t.of_int (Array1.dim str)
let len_ullong str = Unsigned.ULLong.of_int (Array1.dim str)
let to_ptr str = bigarray_start array1 str
*)
let zero str pos len = (Array1.fill (Array1.sub str pos len) '\x00')
let to_bytes str =
let str' = Bytes.create (Array1.dim str) in
Bytes.iteri (fun i _ -> Bytes.set str' i (Array1.unsafe_get str i)) str';
str'
let of_bytes str =
let str' = create (Bytes.length str) in
Bytes.iteri (Array1.unsafe_set str') str;
str'
let sub = Array1.sub
let blit src srcoff dst dstoff len =
Array1.blit (Array1.sub src srcoff len)
(Array1.sub dst dstoff len)