blob: ed9df85726ead59935a0ddfd4dcc215096e2b675 (
plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
open import Basic_classes
open import Bool
open import Num
open import Show
open import Error
declare {ocaml} rename module = bitstring_local
type bitstring
declare ocaml target_rep type bitstring = `Bitstring.bitstring`
(** [empty] is the empty bitstring.
*)
val empty : bitstring
declare ocaml target_rep function empty = `Bitstring.empty`
(** [zeros m] creates a bitstring of length [m] containing all zeros.
*)
val zeros : nat -> bitstring
declare ocaml target_rep function zeros = `Bitstring.create_bitstring`
(** [create m c] creates a bitstring of length [m] containing all [c]
* characters.
*)
val create : nat -> char -> bitstring
declare ocaml target_rep function create = `Bitstring.make_bitstring`
(** [concat xs] concatenates a list of bitstrings [xs] into a single bitstring.
*)
val concat : list bitstring -> bitstring
declare ocaml target_rep function concat = `Bitstring.concat`
(** [acquire fname] acquires a bitstring from a binary file, located at [fname].
*)
val acquire : string -> error bitstring
declare ocaml target_rep function acquire = `Ml_bindings.acquire_bitstring`
(** [length bs0] returns the length of bitstring [bs0].
*)
val length : bitstring -> nat
declare ocaml target_rep function length = `Bitstring.bitstring_length`
(** [partition offset bs0] cuts [bs0] into two pieces at offset [offset]. Throws
* an exception if
*)
val partition : nat -> bitstring -> (bitstring * bitstring)
declare ocaml target_rep function partition = `Ml_bindings.partition_bitstring`
(** [offset_and_cut offset size bs0] cuts a [size]-lengthed bitstring out of [bs0]
* at offset [offset].
*)
val offset_and_cut : nat -> nat -> bitstring -> bitstring
let offset_and_cut offset size bs0 =
let (_, cut) = partition offset bs0 in
let (rel, _) = partition size cut in
rel
(** [equal bs0 bs1] tests whether [bs0] and [bs1] are equal.
*)
val equal : bitstring -> bitstring -> bool
declare ocaml target_rep function equal = unsafe_structural_equality
(** [string_of_bitstring bs0] produces a string-based representation of bitstring
* [bs0].
*)
val string_of_bitstring : bitstring -> string
declare ocaml target_rep function string_of_bitstring = `Bitstring.string_of_bitstring`
instance (Eq bitstring)
let (=) = equal
let (<>) l r = not (equal l r)
end
instance (Show bitstring)
let show = string_of_bitstring
end
|