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
88
89
90
91
92
93
94
95
96
97
98
99
100
type endianness = Big_endian | Little_endian [@@deriving hash]
let default_endianness = Big_endian
let set_int32 endianness bytes offset value =
match endianness with
| Big_endian -> Bytes.set_int32_be bytes offset value
| Little_endian -> Bytes.set_int32_le bytes offset value
let get_int32 endianness bytes offset =
match endianness with
| Big_endian -> Bytes.get_int32_be bytes offset
| Little_endian -> Bytes.get_int32_le bytes offset
let get_int32_string endianness s off =
match endianness with
| Big_endian -> Bytes.get_int32_be (Bytes.unsafe_of_string s) off
| Little_endian -> Bytes.get_int32_le (Bytes.unsafe_of_string s) off
let set_int8 = Bytes.set_int8
let get_int8 = Bytes.get_int8
let get_int8_string s off = Bytes.get_int8 (Bytes.unsafe_of_string s) off
let set_int16 endianness bytes offset value =
match endianness with
| Big_endian -> Bytes.set_int16_be bytes offset value
| Little_endian -> Bytes.set_int16_le bytes offset value
let get_int16 endianness bytes offset =
match endianness with
| Big_endian -> Bytes.get_int16_be bytes offset
| Little_endian -> Bytes.get_int16_le bytes offset
let get_int16_string endianness s off =
match endianness with
| Big_endian -> Bytes.get_int16_be (Bytes.unsafe_of_string s) off
| Little_endian -> Bytes.get_int16_le (Bytes.unsafe_of_string s) off
let set_int64 endianness bytes offset value =
match endianness with
| Big_endian -> Bytes.set_int64_be bytes offset value
| Little_endian -> Bytes.set_int64_le bytes offset value
let get_int64 endianness bytes offset =
match endianness with
| Big_endian -> Bytes.get_int64_be bytes offset
| Little_endian -> Bytes.get_int64_le bytes offset
let get_int64_string endianness s off =
match endianness with
| Big_endian -> Bytes.get_int64_be (Bytes.unsafe_of_string s) off
| Little_endian -> Bytes.get_int64_le (Bytes.unsafe_of_string s) off
let get_uint8 = Bytes.get_uint8
let get_uint8_string s off = Bytes.get_uint8 (Bytes.unsafe_of_string s) off
let get_uint16 endianness bytes offset =
match endianness with
| Big_endian -> Bytes.get_uint16_be bytes offset
| Little_endian -> Bytes.get_uint16_le bytes offset
let get_uint16_string endianness s off =
match endianness with
| Big_endian -> Bytes.get_uint16_be (Bytes.unsafe_of_string s) off
| Little_endian -> Bytes.get_uint16_le (Bytes.unsafe_of_string s) off
let get_double buff i = Int64.float_of_bits (Bytes.get_int64_be buff i)
let get_double_string buff i =
Int64.float_of_bits (Bytes.get_int64_be (Bytes.unsafe_of_string buff) i)
let set_double buff i v = Bytes.set_int64_be buff i (Int64.bits_of_float v)